package com.pub.tools;

/**
 * Title: 基本工具操作类
 */
import com.sun.crypto.provider.SunJCE;
import oracle.jdbc.driver.OracleResultSet;
import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

import javax.servlet.http.HttpSession;
import java.io.*;
import java.math.BigDecimal;
import java.net.InetAddress;
import java.net.URLEncoder;
import java.net.UnknownHostException;
import java.security.Security;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StaticTools {

	public static final String stringDate() {
		//		XYChart c = new XYChart(810, 850);

		String strFormat = "yyyy-MM-dd";
		SimpleDateFormat sdFormat = new SimpleDateFormat(strFormat);
		String strDate = "";
		try {
			Date date = new Date();
			strDate = sdFormat.format(date);
		} catch (Exception exception) {
		}
		return strDate;
	}

	/**
	 * 是否为整形数字
	 * @param  : String
	 * @return : boolean /true --是 /false --否
	 */
	public final static boolean isInteger(String str)
			throws NumberFormatException {
		try {
			if ((str == null) || (str.equals(""))) {
				return false;
			} else {
				str = str.trim();
			}
			int thisInt = (new Integer(str)).intValue();
			if (thisInt < 0) {
				return false;
			} else {
				return true;
			}
		} catch (Exception e) {
			return false;
		}
	}

	/**
	 * 是否为数字
	 * @param  : String
	 * @return : boolean /true --是 /false --否
	 */
	public final static boolean isNumeric(String str)
			throws NumberFormatException {
		try {
			if ((str == null) || (str.equals(""))) {
				return false;
			} else {
				str = str.trim();
			}
			float thisfloat = (new Float(str)).floatValue();
			if (thisfloat < 0) {
				return false;
			} else {
				return true;
			}
		} catch (Exception e) {
			return false;
		}
	}

	/**
	 * 是否为数字
	 * @param  : String
	 * @return : boolean /true --是 /false --否
	 */
	public final static boolean isNum(String str)
			throws NumberFormatException {
		try {
			if ((str == null) || (str.equals(""))) {
				return false;
			} else {
				str = str.trim();
			}
			float thisfloat = (new Float(str)).floatValue();
			return true;
		} catch (Exception e) {
			return false;
		}
	}

	/**
	 * 字符串转为日期
	 * @param  : String
	 * @return : Date
	 */
	public final static Date stringToDate(String str) {
		str = StaticTools.tostanddate(str);
		String strFormat = "yyyy-MM-dd HH:mm";
		if (str != null && str.length() == 10) {
			strFormat = "yyyy-MM-dd";
		}
		SimpleDateFormat sdFormat = new SimpleDateFormat(strFormat);
		Date date = new Date();
		try {
			date = sdFormat.parse(str);
		} catch (Exception e) {
			Date date1 = null;
			return date1;
		}
		return date;
	}

	/**
	 * 得到本地机器名
	 * @return : String
	 */
	public final static String getLocaMac() {
		String strchar = "";
		try {
			String s1 = "ipconfig /all";
			Process process = Runtime.getRuntime().exec(s1);
			BufferedReader bufferedreader =
					new BufferedReader(
							new InputStreamReader(process.getInputStream()));
			String line = bufferedreader.readLine();
			do {
				if (line == null) {
					break;
				}
				String nextLine = bufferedreader.readLine();
				if (line.indexOf("Physical Address") > 0) {
					int i = line.indexOf("Physical Address") + 36;
					strchar = line.substring(i);
					break;
				}
				line = nextLine;
			} while (true);
			bufferedreader.close();
			process.waitFor();
		} catch (Exception exception) {
			strchar = "";
		}
		return strchar.trim();
	}

	/**
	 * 得到本地机器ip地址
	 * @return: String
	 */
	public final static String getLocalIP() {
		String strchar = "";
		try {
			strchar = InetAddress.getLocalHost().getHostAddress().toString();
		} catch (UnknownHostException unknownhostexception) {
		}
		return strchar;
	}
	/**
	 * 得到本地机器ip地址,如果存在多个ip,只返回与传入参数匹配的ip
	 * @return: String
	 */
	public final static String getLocalIP(String net) {
		String strchar = "";
		try {
			InetAddress[] all;
			all =
					InetAddress.getAllByName(
							InetAddress.getLocalHost().getHostName());
			for (int i = 0; i < all.length; i++) {
				if (all[i].getHostAddress().startsWith(net)) {
					strchar = all[i].getHostAddress();
					break;
				}
			}

		} catch (UnknownHostException unknownhostexception) {
		}
		return strchar;
	}

	/**
	 * 得到汉字星期值
	 * @param : Date
	 * @return: String 汉字星期值
	 */
	public final static String dateToWeek(Date dt) {
		int iDay = dt.getDay();
		String temp = "";
		switch (iDay) {
			case 0 : // '\0'
				temp = "星期天";
				break;

			case 1 : // '\001'
				temp = "星期一";
				break;

			case 2 : // '\002'
				temp = "星期二";
				break;

			case 3 : // '\003'
				temp = "星期三";
				break;

			case 4 : // '\004'
				temp = "星期四";
				break;

			case 5 : // '\005'
				temp = "星期五";
				break;

			case 6 : // '\006'
				temp = "星期六";
				break;

			default :
				temp = "";
				break;
		}
		return temp;
	}

	/**
	 * 得到某个日期 前/后 N日 的日期值
	 * @param: Date
	 * @param: int   日 (  + 为后N日/ - 为前N日)
	 * @return : Date
	 */
	public final static Date dayDiv(Date dt, int days) {
		return new Date(dt.getYear(), dt.getMonth(), dt.getDate() + days);
	}

	/**
	 * 得到某个日期 前/后 N月 的日期值
	 * @param: Date
	 * @param: int   月 (  + 为后N月/ - 为前N月)
	 * @return : Date
	 */
	public final static Date monthDiv(Date dt, int months) {
		return new Date(dt.getYear(), dt.getMonth() + months, dt.getDate());
	}

	/**
	 * 得到某个日期 前/后 N年 的日期值
	 * @param: Date
	 * @param: int   年 (  + 为后N年/ - 为前N年)
	 * @return : Date
	 */
	public final static Date yearDiv(Date dt, int years) {
		return new Date(dt.getYear() + years, dt.getMonth(), dt.getDate());
	}

	/**
	 * 得到某个日期 后N年/月/日/小时/分钟/秒 的日期值
	 * @param: Date
	 * @param: int
	 * @param: String  年/月/日/小时/分钟/秒
	 * @return : Date
	 */
	public final static Date dayAfter(
			Date dDate,
			int nInterval,
			String sFormat) {
		int nFormat = 0;
		if (sFormat.equals("月")) {
			nFormat = 1;
		}
		if (sFormat.equals("日")) {
			nFormat = 2;
		}
		if (sFormat.equals("小时")) {
			nFormat = 3;
		}
		if (sFormat.equals("分钟")) {
			nFormat = 4;
		}
		if (sFormat.equals("秒")) {
			nFormat = 5;
		}
		Date nextDay = null;
		switch (nFormat) {
			case 0 :
				nextDay =
						new Date(
								dDate.getYear() + nInterval,
								dDate.getMonth(),
								dDate.getDate(),
								dDate.getHours(),
								dDate.getMinutes(),
								dDate.getSeconds());
				break;
			case 1 :
				nextDay =
						new Date(
								dDate.getYear(),
								dDate.getMonth() + nInterval,
								dDate.getDate(),
								dDate.getHours(),
								dDate.getMinutes(),
								dDate.getSeconds());
				break;

			case 2 :
				nextDay =
						new Date(
								dDate.getYear(),
								dDate.getMonth(),
								dDate.getDate() + nInterval,
								dDate.getHours(),
								dDate.getMinutes(),
								dDate.getSeconds());
				break;

			case 3 :
				nextDay =
						new Date(
								dDate.getYear(),
								dDate.getMonth(),
								dDate.getDate(),
								dDate.getHours() + nInterval,
								dDate.getMinutes(),
								dDate.getSeconds());
				break;

			case 4 :
				nextDay =
						new Date(
								dDate.getYear(),
								dDate.getMonth(),
								dDate.getDate(),
								dDate.getHours(),
								dDate.getMinutes() + nInterval,
								dDate.getSeconds());
				break;

			case 5 :
				nextDay =
						new Date(
								dDate.getYear(),
								dDate.getMonth(),
								dDate.getDate(),
								dDate.getHours(),
								dDate.getMinutes(),
								dDate.getSeconds() + nInterval);
				break;
		}
		return nextDay;
	}

	/**
	 * 得到大写年份
	 * @param  iyear  数字年份
	 * @return String  大写年份
	 */
	public final static String getChinYear(String iyear) {
		String cyear = "";
		for (int s = 0; s < iyear.trim().length(); s++) {
			if (iyear.substring(s, s + 1).equals("1")) {
				cyear += "一";
			}
			if (iyear.substring(s, s + 1).equals("2")) {
				cyear += "二";
			}
			if (iyear.substring(s, s + 1).equals("3")) {
				cyear += "三";
			}
			if (iyear.substring(s, s + 1).equals("4")) {
				cyear += "四";
			}
			if (iyear.substring(s, s + 1).equals("5")) {
				cyear += "五";
			}
			if (iyear.substring(s, s + 1).equals("6")) {
				cyear += "六";
			}
			if (iyear.substring(s, s + 1).equals("7")) {
				cyear += "七";
			}
			if (iyear.substring(s, s + 1).equals("8")) {
				cyear += "八";
			}
			if (iyear.substring(s, s + 1).equals("9")) {
				cyear += "九";
			}
			if (iyear.substring(s, s + 1).equals("0")) {
				cyear += "O";
			}
		}
		return iyear;
	}

	/**
	 * 得到大写月份
	 * @param imonth String    数字月份
	 * @return String   大写月份
	 */
	public final static String getChinMonth(String imonth) {
		imonth = imonth.trim();
		if (imonth.equals("0")) {
			return "零";
		}
		if (imonth.equals("1")) {
			return "一";
		}
		if (imonth.equals("2")) {
			return "二";
		}
		if (imonth.equals("3")) {
			return "三";
		}
		if (imonth.equals("4")) {
			return "四";
		}
		if (imonth.equals("5")) {
			return "五";
		}
		if (imonth.equals("6")) {
			return "六";
		}
		if (imonth.equals("7")) {
			return "七";
		}
		if (imonth.equals("8")) {
			return "八";
		}
		if (imonth.equals("9")) {
			return "九";
		}
		if (imonth.equals("10")) {
			return "十";
		}
		if (imonth.equals("11")) {
			return "十一";
		}
		if (imonth.equals("12")) {
			return "十二";
		}
		return imonth;
	}

	/**
	 * 将字符串按分隔符进行拆分
	 * @param  instring String   字符串
	 * @param  splitsign String  分隔符
	 * @return ArrayList
	 */
	public final static ArrayList splitString(
			String instring,
			String splitsign) {
		ArrayList tmparr = new ArrayList();
		if (instring.trim().equals("")) {
			return tmparr;
		}
		String intmp = "";
		int t = 0;
		for (int i = 0; i < instring.length(); i++) {
			if (instring.substring(i, i + 1).equals(splitsign)) {
				tmparr.add(intmp);
				intmp = "";
			} else {
				intmp += instring.substring(i, i + 1);
			}
		}
		tmparr.add(instring.substring(instring.lastIndexOf(splitsign) + 1));
		return tmparr;
	}
	/**
	 * 将字符串按分隔符进行拆分
	 * @param  instring  字符串
	 * @param  splitsign 分隔符
	 * @return ArrayList
	 */
	public final static String[] splitStr(String instring, String splitsign) {
		ArrayList tmparr = new ArrayList();
		tmparr = splitString(instring, splitsign);
		String[] tmp = { "" };

		if (tmparr.size() > 0) {
			tmp = new String[tmparr.size()];
			for (int i = 0; i < tmparr.size(); i++) {
				tmp[i] = (String) tmparr.get(i);
			}

		}

		return tmp;
	}
	/**
	 * 统计字符串中 特定字符出现的次数
	 * @param  instring String   字符串
	 * @param  sign String  分隔符
	 * @return ArrayList
	 */
	public final static int countNumber(String instring, String sign) {
		int realnum = 0;
		for (int i = 0; i < instring.length(); i++) {
			if (instring.substring(i, i + 1).equals(sign)) {
				realnum++;
			}
		}
		return realnum;
	}

	/**
	 * 校验身份证号码
	 * @param  idcard  身份证号
	 * @return boolean 号码是否正确  true/false
	 */
	public final static boolean VerifyIDCard(String idcard) {
		if (idcard.length() == 15) {
			idcard = uptoeighteen(idcard);
		}
		if (idcard.length() != 18) {
			return false;
		}
		String verify = idcard.substring(17, 18);
		if (verify.equals(getVerify(idcard))) {
			return true;
		}
		return false;
	}

	private static String uptoeighteen(String fifteencardid) {
		String eightcardid = fifteencardid.substring(0, 6);
		eightcardid = eightcardid + "19";
		eightcardid = eightcardid + fifteencardid.substring(6, 15);
		eightcardid = eightcardid + getVerify(eightcardid);
		return eightcardid;
	}

	private static String getVerify(String eightcardid) {
		int remaining = 0;
		int[] ai = new int[18];
		int[] wi = { 7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2, 1 };
		int[] vi = { 1, 0, 'X', 9, 8, 7, 6, 5, 4, 3, 2 };

		if (eightcardid.length() == 18) {
			eightcardid = eightcardid.substring(0, 17);
		}
		if (eightcardid.length() == 17) {
			int sum = 0;
			for (int i = 0; i < 17; i++) {
				String k = eightcardid.substring(i, i + 1);
				ai[i] = Integer.parseInt(k);
			}
			for (int i = 0; i < 17; i++) {
				sum = sum + wi[i] * ai[i];
			}
			remaining = sum % 11;
		}
		return remaining == 2 ? "X" : String.valueOf(vi[remaining]);
	}

	/**
	 * 将大写转为数字
	 * @param  instring String 大写
	 * @return double 数字
	 */
	public final static double hzptconver(String instring) {
		String hz1 = "", hz2 = "", hz3 = "";
		double je1 = 0.0, je2 = 0.0, je3 = 0.0;
		String hzchk1 = "拾百千";
		String hzchk3 = "零壹贰叁肆伍陆柒捌玖";

		int tt = instring.indexOf("万");
		if (tt > 0) {
			hz1 = instring.substring(0, tt + 1);
			hz3 = instring.substring(tt + 1, instring.length());
		} else {
			hz3 = instring;
		}
		if (!hz1.equals("")) {
			int j = 0, k = 0;
			for (int i = 0; i < hz1.length(); i++) {
				j = hzchk3.indexOf(hz1.substring(i, i + 1));
				if (j > 0) {
					k = j;
				} else {
					if (hzchk1.indexOf(hz1.substring(i, i + 1)) == 0) {
						je1 = je1 + k * 10;
						k = 0;
					} else if (hzchk1.indexOf(hz1.substring(i, i + 1)) == 1) {
						je1 = je1 + k * 100;
						k = 0;
					} else if (hzchk1.indexOf(hz1.substring(i, i + 1)) == 2) {
						je1 = je1 + k * 1000;
						k = 0;
					} else {
						je1 = je1 + k;
						k = 0;
					}
				}
			}
			je1 = je1 * 10000;
		}

		tt = hz3.indexOf("点");
		if (tt > 0) {
			hz2 = hz3.substring(tt + 1, hz3.length());
			hz3 = hz3.substring(0, tt);
		}

		if (!hz2.equals("")) {
			int j = 0, k = 0;
			String jedx = "";
			for (int i = 0; i < hz2.length(); i++) {
				j = hzchk3.indexOf(hz2.substring(i, i + 1));
				jedx = jedx + String.valueOf(j);
			}
			je2 = Double.parseDouble("0." + jedx);
		}

		if (!hz3.equals("")) {
			int j = 0, k = 0;
			for (int i = 0; i < hz3.length(); i++) {
				j = hzchk3.indexOf(hz3.substring(i, i + 1));
				if (j > 0) {
					k = j;
				}
				if (j > 0 && i == hz3.length() - 1) {
					je3 = je3 + k;
				} else if (hzchk1.indexOf(hz3.substring(i, i + 1)) == 0) {
					je3 = je3 + k * 10;
					k = 0;
				} else if (hzchk1.indexOf(hz3.substring(i, i + 1)) == 1) {
					je3 = je3 + k * 100;
					k = 0;
				} else if (hzchk1.indexOf(hz3.substring(i, i + 1)) == 2) {
					je3 = je3 + k * 1000;
					k = 0;
				}
			}
		}
		return je1 + je2 + je3;
	}

	/**
	 * 将大写金额转为数字金额
	 * @param  instring String 大写金额
	 * @return double 数字金额
	 */
	public final static double hzjeconvert(String instring) {
		String hz1 = "", hz2 = "", hz3 = "";
		double je1 = 0.0, je2 = 0.0, je3 = 0.0;
		String hzchk1 = "拾佰仟";
		String hzchk2 = "角分";
		String hzchk3 = "零壹贰叁肆伍陆柒捌玖";
		int tt = instring.indexOf("万");
		if (tt > 0) {
			hz1 = instring.substring(0, tt + 1);
			hz2 = instring.substring(tt + 1, instring.length());
		} else {
			hz2 = instring;
		}
		if (!hz1.equals("")) {
			int j = 0, k = 0;
			for (int i = 0; i < hz1.length(); i++) {
				j = hzchk3.indexOf(hz1.substring(i, i + 1));
				if (j > 0) {
					k = j;
				} else {
					if (hzchk1.indexOf(hz1.substring(i, i + 1)) == 0) {
						je1 = je1 + k * 10;
						k = 0;
					} else if (hzchk1.indexOf(hz1.substring(i, i + 1)) == 1) {
						je1 = je1 + k * 100;
						k = 0;
					} else if (hzchk1.indexOf(hz1.substring(i, i + 1)) == 2) {
						je1 = je1 + k * 1000;
						k = 0;
					} else {
						je1 = je1 + k;
						k = 0;
					}
				}
			}
			je1 = je1 * 10000;
		}

		tt = hz2.indexOf("元");
		if (tt > 0) {
			hz3 = hz2.substring(0, tt + 1);
			hz2 = hz2.substring(tt + 1, hz2.length());
		}

		if (!hz2.equals("")) {
			int j = 0, k = 0;
			for (int i = 0; i < hz2.length(); i++) {
				j = hzchk3.indexOf(hz2.substring(i, i + 1));
				if (j > 0) {
					k = j;
				} else {
					if (hzchk2.indexOf(hz2.substring(i, i + 1)) == 0) {
						je2 = je2 + k * 10;
						k = 0;
					}
					if (hzchk2.indexOf(hz2.substring(i, i + 1)) == 1) {
						je2 = je2 + k;
						k = 0;
					}
				}
			}
			je2 = je2 * 0.01;
		}

		if (!hz3.equals("")) {
			int j = 0, k = 0;
			for (int i = 0; i < hz3.length(); i++) {
				j = hzchk3.indexOf(hz3.substring(i, i + 1));
				if (j > 0) {
					k = j;
				} else if (hzchk1.indexOf(hz3.substring(i, i + 1)) == 0) {
					je3 = je3 + k * 10;
					k = 0;
				} else if (hzchk1.indexOf(hz3.substring(i, i + 1)) == 1) {
					je3 = je3 + k * 100;
					k = 0;
				} else if (hzchk1.indexOf(hz3.substring(i, i + 1)) == 2) {
					je3 = je3 + k * 1000;
					k = 0;
				} else {
					je3 = je3 + k;
					k = 0;
				}
			}
		}

		return je1 + je2 + je3;
	}

	/**
	 * 将数字格式化成财务记数法
	 * @para   String  数字字符串
	 * @return String  财务记数法字符串
	 */
	public final static String fnumber(String innum) {

		String xs = "";
		if (innum.indexOf(".") > 0) {
			xs = innum.substring(innum.indexOf("."));
			innum = innum.substring(0, innum.indexOf("."));
		}
		String zf = "";
		if (innum.startsWith("-")) {
			zf = "-";
			innum = innum.substring(1);
		}

		if (innum.length() > 3) {
			int inum = innum.length();
			if (inum <= 6) {
				innum =
						innum.substring(0, inum - 3)
								+ ","
								+ innum.substring(inum - 3);
			} else {
				if (inum <= 9) {
					innum =
							innum.substring(0, inum - 6)
									+ ","
									+ innum.substring(inum - 6, inum - 3)
									+ ","
									+ innum.substring(inum - 3);
				} else {
					innum =
							innum.substring(0, inum - 9)
									+ ","
									+ innum.substring(inum - 9, inum - 6)
									+ ","
									+ innum.substring(inum - 6, inum - 3)
									+ ","
									+ innum.substring(inum - 3);
				}
			}
		}
		return zf + innum + xs;
	}

	/**
	 * 字符替换
	 * 本方法把一些需要屏蔽的字符串改为对应的中文字符。这样在执行数据表操作时不会出错
	 * @param  str   需要处理的字符串
	 * @return (String)       处理后的字符串
	 */
	public final static String formatForSql(String str) {
		if (str == null) {
			str = "";
		} else {
			str = str.trim();
			str = replaceString(str, "'", "‘");
			str = replaceString(str, "\"", "“");
			str = replaceString(str, "#", "＃");

		}
		return str;
	}
	/**
	 * 字符替换
	 * 本方法把一些需要屏蔽的字符串改为对应的中文字符。这样在执行数据表操作时不会出错
	 * @param  str   需要处理的字符串
	 * @return (String)       处理后的字符串
	 */
	public final static String formatForChar(String str) {
		if (str == null) {
			str = "";
		} else {
			str = str.trim();
		}
		return str;
	}
	/**
	 * 字符替换
	 * 本方法把一些需要屏蔽的字符串改为对应的中文字符。这样在执行数据表操作时不会出错
	 * @param   str   需要处理的字符串
	 * @return (String)       处理后的字符串
	 */
	public final static String formatForHtml(String str) {
		if (str == null) {
			str = "";
		} else {
			str = str.trim();
			str = replaceString(str, "'", "‘");
			str = replaceString(str, "\"", "“");
			str = replaceString(str, "#", "＃");
		}
		return str;
	}

	/**
	 * 字符替换
	 * @param  Str (String)    需要处理的字符串
	 * @param  Sou (String) sou   需要替换掉的字符串
	 * @param  Des (String) des   需要替换为的字符串
	 * @return (String)       处理后的字符串
	 */
	public final static String replaceString(
			String Str,
			String Sou,
			String Des) {
		int startIndex;
		int endIndex;
		String startString;
		String endString;
		String compString = "";
		int i, j;
		if (Str == null) {
			Str = "";
			compString = Str;
		} else {
			compString = Str;
		}
		i = 0;
		j = Str.length();
		while (i < j) {
			startIndex = Str.indexOf(Sou);
			if (startIndex >= 0) { //存在出现位置
				endIndex = startIndex + Sou.length(); //结束位置
				startString = Str.substring(0, startIndex); //在这之前的字符
				if (startString == null) {
					startString = "";
				}
				endString = Str.substring(endIndex, Str.length()); //在这之后的字符
				if (endString == null) {
					endString = "";
				}
				compString = startString + Des + endString; //返回字符串
				Str = compString; //原字符串改为新串
				i = startIndex + Des.length(); //设置新的查询起点
				j = compString.length(); //设置新的查询结束点
			} else {
				i = j;
			}
		}
		return compString;
	}

	/**
	 * 将汉字字符串转换为汉语拼音首字母串
	 * @param  instring (String) instring -- 需转换的字符串
	 * @return (String)   汉语拼音字母串
	 */
	public final static String converthz(String instring) {
		if (instring.trim().length() == 0) {
			return "";
		}
		instring = instring.trim().toUpperCase();
		String spinyin = "", bword = "";
		String shz = "啊芭擦搭蛾发噶哈击喀拉妈拿哦啪期然撒塌挖昔压匝座";
		String szm = "ABCDEFGHJKLMNOPQRSTWXYZZ";

		for (int i = 0; i < instring.trim().length(); i++) {
			bword = instring.trim().substring(i, i + 1);
			int ifin = 1;
			for (int j = 0; j < shz.length() - 1; j++) {
				try {
					if (encodingToIso(bword)
							.compareTo(encodingToIso(shz.substring(j, j + 1)))
							>= 0) {
						if (encodingToIso(bword)
								.compareTo(
										encodingToIso(shz.substring(j + 1, j + 2)))
								< 0) {
							spinyin = spinyin + szm.substring(j, j + 1);
							ifin = 2;
						}
					}
				} catch (IOException ioe) {
				}
			}

			String newpinyin = pripinyin(bword);
			if (!newpinyin.equals("")) {
				spinyin = spinyin + newpinyin;
				ifin = 2;
			}
			if (ifin < 2) {
				spinyin += bword;
			}
		}
		return spinyin;
	}

	//处理特殊字符
	private final static String pripinyin(String spy) {
		String newpy = "";
		if (spy.equals("座")) {
			newpy = "Z";
		}
		if (spy.equals("铠")) {
			newpy = "K";
		}
		if (spy.equals("楠")) {
			newpy = "N";
		}
		if (spy.equals("孚")) {
			newpy = "F";
		}
		if (spy.equals("炜")) {
			newpy = "W";
		}
		if (spy.equals("鄯")) {
			newpy = "S";
		}
		if (spy.equals("矸")) {
			newpy = "G";
		}
		if (spy.equals("兖")) {
			newpy = "Y";
		}
		if (spy.equals("耦")) {
			newpy = "O";
		}
		if (spy.equals("鑫")) {
			newpy = "X";
		}
		if (spy.equals("圩")) {
			newpy = "W";
		}
		if (spy.equals("柚")) {
			newpy = "Y";
		}
		if (spy.equals("莹")) {
			newpy = "Y";
		}

		return newpy;
	}

	/**
	 * 将字符串的编码方式改为ISO 方式
	 *  字符串
	 * @return String
	 */
	public final static String encodingToIso(String str)
			throws IOException, UnsupportedEncodingException {
		str = new String(str.getBytes("GB2312"), "8859_1");
		return str;
	}

	/**
	 * 字符串转为浮点数
	 * @param   str 需转换 的数据
	 * @return  float  转换后 的数据
	 */
	public final static float stringToFloat(String str) {
		float result = (float) 0.0;
		try {
			if (str == null) {
				return 0;
			} else {
				if (str.equals("")) {
					return 0;
				} else {
					result = (new Float(str.trim())).floatValue();
				}
			}
		} catch (Exception e) {
			result = (float) 0.0;
		}
		return result;
	}

	/**
	 * 字符串转为整数
	 *
	 * @param   str 需转换 的数据
	 * @return  int    转换后 的数据
	 */
	public final static int stringToInt(String str) {

		int result = 0;
		try {
			if (str == null) {
				return 0;
			} else {
				if (str.equals("")) {
					return 0;
				} else {
					result = (new Integer(str.trim())).intValue();
				}
			}
			return result;
		} catch (Exception e) {
			return 0;
		}
	}

	/**
	 * Unicode and Iso 互相转换
	 *
	 * @param   str 需转换的字符串
	 * @return （String）  转换后的字符串
	 */

	public final static String encodingMethodOne(String str)
			throws IOException, UnsupportedEncodingException {

		return (str == null)
				? ""
				: new String(str.getBytes("8859_1"), "GB2312");
	}

	public final static String encodingMethodThr(String str)
			throws IOException, UnsupportedEncodingException {

		return (str == null) ? "" : new String(str.getBytes("UTF-8"), "GBK");
	}
	public final static String encodingMethodFou(String str)
			throws IOException, UnsupportedEncodingException {

		return (str == null) ? "" : new String(str.getBytes("GBK"), "UTF-8");
	}
	public final static String encodingMethodTwo(String str)
			throws IOException, UnsupportedEncodingException {

		if (str == null) {
			return "";
		}
		byte[] temp = str.getBytes("8859_1");
		return new String(temp, "GB2312");
	}

	public final static String encodForUrl(String str)
			throws IOException, UnsupportedEncodingException {
		return (str == null) ? "" : URLEncoder.encode(str);
	}

	/**
	 * 字符串补位
	 * @param  weishu (int)       －补位后的总位数
	 * @param  num(String)       --需补位的字符串
	 * @param  addchar(String)   --补位字符 (一位字符 空格为 " ")
	 * @param  addloc(int)       --补位位置(1..前补位  2..后补位)
	 * @return (String)          --补位后的字符串
	 */
	public static final String ForAddWord(
			int weishu,
			String num,
			String addchar,
			int addloc) {
		return ForAddWord(weishu, num, addchar, addloc, 0);
	}

	private static final String ForAddWord(
			int weishu,
			String num,
			String addchar,
			int addloc,
			int mode) {
		if (num.length() >= weishu) {
			return num;
		}
		int i = 0;
		int j = weishu - num.length();

		String BH = "";
		while (i < j) {
			BH += addchar;
			i++;
		}
		if (addloc < 2) {
			return BH + num;
		} else {
			return num + BH;
		}
	}

	/**
	 * 将字符串设置为定长
	 * 位数不足时，补空格
	 * @param  : String 字符串
	 * @param  : int 长度
	 * @return : String
	 */
	public static final String ForWord(String inword, int wordlen) {
		if (wordlen < 1) {
			return inword;
		}
		if (inword.length() < wordlen) {
			return ForAddWord(wordlen, inword, " ", 2, 1);
		}
		if (inword.length() > wordlen) {
			return inword.substring(0, wordlen);
		}
		return inword;

	}

	/**
	 * 浮点数求余
	 * @param  up float 浮点数 除数
	 * @param  down float 浮点数 被除数
	 * @return int 余数
	 */
	public final static int getMod(float up, float down) throws IOException {
		int result = 0;
		float dev = up / down;
		result = (int) dev;
		result = dev > result ? result + 1 : result;

		return result;
	}

	/**
	 * 检查给定的字符串是否在给定的字符串数组中
	 *
	 * @param  str -- 给定的字符串 strs --给定的字符串数组
	 * @return (boolean) ture--在   false--不在
	 *
	 */
	public static final boolean strisInStringArray(String str, String[] strs) {
		boolean inTag = false;
		for (int i = 0; i < strs.length; i++) {
			if (str.equals(strs[i])) {
				inTag = true;
				break;
			}
		}
		return inTag;
	}

	/**
	 * 检查给定的字符串在给定的字符串数组中的位置
	 *
	 * str -- 给定的字符串 strs --给定的字符串数组
	 * @return int 位置
	 *
	 */
	public static final int stringInStringArrayIndex(
			String str,
			String[] strs) {
		int ret = -1;
		for (int i = 0; i < strs.length; i++) {
			if (str.equals(strs[i])) {
				ret = i;
				break;
			}
		}
		return ret;
	}

	/**
	 * 反格式化字符串,使其可用于程序中的字符数据类型.
	 *
	 * old 转换前的字符串.
	 * @return (String)转换后的字符串,处理字符串中的"'";
	 *
	 */
	public static final String unformatStrForSql(String old) {
		if (old == null) {
			return "";
		}
		old = old.trim();
		String values = "";
		String c = "‘";
		int start = 0;
		int pos;
		while ((pos = old.indexOf(c, start)) >= 0) {
			values += old.substring(start, pos) + "'";
			start = pos + 1;
		}
		values += old.substring(start);
		return values;
	}

	/**
	 * 校验电子邮箱地址 (空串不校验)
	 *
	 * @param str 电子邮件地址
	 * @return (boolean) true --正确  false --不正确
	 *
	 */
	public static final boolean isEmail(String str) {
		if (str.length() < 1) {
			return true;
		}
		int Ihoutou = str.indexOf('@');
		int Ipoint = str.lastIndexOf('.');
		int Elength = str.trim().length();

		if ((Ihoutou == -1)
				|| (Ihoutou == 0)
				|| (Ipoint == -1)
				|| (Ipoint == Elength)) {
			return false;
		}
		return true;
	}

	/**
	 * 字符串小数表示法 格式化
	 *
	 * @param  instring 需格式化的字符串
	 * @param   dotloc   小数个数
	 * @return String
	 */
	public final static String dotFormat(String instring, int dotloc) {

		instring = instring.trim();

		if (dotloc < 0) {
			return instring;
		}
		if (instring.length() <= dotloc + 1) {
			return instring;
		}
		if (instring.indexOf(".") == -1) {
			return instring;
		}

		if (instring.length() < instring.indexOf(".") + dotloc) {
			return instring;
		}
		if (dotloc == 0) {
			return instring.substring(0, instring.indexOf("."));
		}
		if (instring
				.substring(instring.indexOf(".") + 1, instring.length())
				.length()
				< dotloc) {
			return instring;
		}
		return instring.substring(0, instring.indexOf(".") + dotloc + 1);

	}

	/**
	 * 字符串小数表示法 格式化为需要的小数位数，不足位的补0
	 *
	 *  instring 需格式化的字符串
	 *     dotloc   小数位数
	 *
	 */
	public final static String dotFormatForZero(String instring, int dotloc) {

		instring = instring.trim();

		//
		if (dotloc == 0) {
			//处理小数位为零的情况
			if (instring.indexOf(".") == -1) {
				return instring;
			} else {
				return instring.substring(0, instring.indexOf("."));
			}
		}
		if (dotloc <= 0) {
			return instring;
		}
		if (instring.indexOf(".") == -1) {
			instring = instring + ".";
			for (int i = 0; i < dotloc; i++) {
				instring = instring + "0";
			}
			return instring;
		}
		String tmpinstr = instring.substring(instring.indexOf(".") + 1);

		if (tmpinstr.length() >= dotloc) {
			tmpinstr = tmpinstr.substring(0, dotloc);
			instring =
					instring.substring(0, instring.indexOf(".") + 1) + tmpinstr;

			return instring;
		}
		if (instring
				.substring(instring.indexOf(".") + 1, instring.length())
				.length()
				< dotloc) {
			int addZeroLength =
					dotloc
							- instring
							.substring(instring.indexOf(".") + 1, instring.length())
							.length();
			for (int m = 0; m < addZeroLength; m++) {
				instring = instring + "0";
			}
			return instring;
		}
		return instring.substring(0, instring.indexOf(".") + dotloc + 1);

	}

	/**
	 * 字符串截取
	 *
	 *  instring 需格式化的字符串
	 *     innumber 需留取的个数
	 * @return String
	 */
	public final static String subString(String instring, int innumber) {

		if (instring == null) {
			return "";
		}
		instring = instring.trim();

		if (innumber < 1) {
			return instring;
		}
		if (instring.length() <= innumber) {
			return instring;
		}

		return instring.substring(0, innumber);

	}

	/**
	 * 统计字符串中 某个字符出现的次数
	 *  字符串
	 *  需统计的字符
	 * @return int 出现的次数
	 */
	public final static int totNumber(String inString, String needchar) {
		int nTotNumber = 0;
		int nFullLength = inString.length();
		int i = 0;
		while (i < nFullLength) {
			if (inString.substring(i, i + 1).equals(needchar)) {
				nTotNumber++;
			}
			i++;
		}
		return nTotNumber;

	}

	/**
	 * 字符串省略截取 格式化
	 *
	 *  instring 需格式化的字符串
	 *     innumber 需留取的个数
	 * @return String
	 */
	public final static String trimString(String instring, int innumber) {

		if (instring == null) {
			return "";
		}
		instring = instring.trim();

		if (innumber < 1) {
			return instring;
		}
		if (instring.length() <= innumber) {
			return instring;
		}

		if (instring.indexOf(".") > 0 && instring.indexOf(":") > 0) {
			return instring.substring(0, innumber);
		} else {
			return instring.substring(0, innumber) + "...";
		}

	}

	/**
	 * 字符串省略截取 格式化,如果为空值，加空字符串
	 *
	 *  instring 需格式化的字符串
	 *     innumber 需留取的个数
	 * @return String
	 */
	public final static String trimStringNull(String instring, int innumber) {

		if (instring == null) {
			return "&nbsp;";
		}
		instring = instring.trim();

		if (innumber < 1) {
			return "&nbsp;";
		}
		if (instring.length() <= innumber) {
			return instring;
		}

		return instring.substring(0, innumber) + "...";

	}

	/**
	 * 将时间戳字段值或日期字段值返回为 XXXX 年 XX 月 XX日 （XX:XX:XX时）字串
	 *
	 *sInstr,时间戳字段或日期字段，如果为空则返回空串
	 *        (int)   nInnum,取值：0，1或3
	 *                       如果是0 则返回形如“XXXX 年 XX 月 XX日”字符串
	 *                       如果是1 则返回形如“XXXX 年 XX 月 XX日 XX:XX:XX 时”字符串
	 *                       如果是2 则返回形如“XXXX - XX - XX XX：XX：XX”字符串
	 *                       如果是3 则表示所传的sInstr参数为日期形字段
	 *
	 *@return (sNewstr) --存放返回的年月（时）值
	 */
	public final static String replaceTime(String sInstr, int nInnum) {

		String sg = sInstr;
		String sgsjful = "";
		String sgsjshot = "";
		String sgsjful_ = "";
		String sNewstr = "";
		if (sg.length() > 10) {
			String sgrq = sg.substring(0, 10);
			String sgs = sg.substring(11, 19);
			String sgn = sgrq.substring(0, 4);
			String sgy = sgrq.substring(5, 7);
			String sgr = sgrq.substring(8, 10);
			sgsjful = " " + sgn + "年" + sgy + "月" + sgr + "日 " + sgs + "时";
			sgsjful_ =
					" "
							+ sgn
							+ "-"
							+ sgy
							+ "-"
							+ sgr
							+ " "
							+ replace(sgs, ".", ":");
			sgsjshot = " " + sgn + "年" + sgy + "月" + sgr + "日 ";
		}

		if (nInnum == 0) {
			sNewstr = sgsjshot;
		}
		if (nInnum == 1) {
			sNewstr = sgsjful;
		}
		if (nInnum == 2) {

			sNewstr = sgsjful_;
		}
		return sNewstr;
	}

	/**
	 * 去掉数字形式的字符串，小数点后的零值
	 *
	 * 数字形式的字符串
	 *@return (String)
	 */
	public final static String remoDotValue(String sInstr) {
		sInstr = sInstr.trim();
		if (sInstr.indexOf(".") < 0) {
			return sInstr;
		}
		if (!isNumeric(sInstr)) {
			return sInstr;
		}
		sInstr =
				sInstr.substring(0, sInstr.indexOf("."))
						+ remoStrDot(sInstr.substring(sInstr.indexOf(".")));
		if (sInstr.endsWith(".")) {
			sInstr = sInstr.substring(0, sInstr.length() - 1);
		}
		return sInstr;
	}

	private final static String remoStrDot(String sInstr) {
		while (sInstr.endsWith("0")) {
			sInstr = sInstr.substring(0, sInstr.length() - 1);
		}
		return sInstr;
	}

	/**
	 * 去掉数字形式的字符串，小数点后的零值
	 * 保留两位小数
	 * @param  : String 数字形式的字符串
	 * @return : String
	 */
	public final static String remoDotValueMoney(String sInstr) {
		sInstr = sInstr.trim();
		if (!isNumeric(sInstr)) {
			return sInstr;
		}
		sInstr = remoDotValue(sInstr);
		if (sInstr.indexOf(".") < 0) {
			return sInstr + ".00";
		}
		if (sInstr.indexOf(".") == (sInstr.length() - 2)) {
			return sInstr + "0";
		}

		return sInstr.substring(0, sInstr.indexOf(".") + 3);
	}

	/**
	 * 格式化数字型字符串
	 *  数字型字符串
	 *  format 格式  财务数字/数字
	 *  decnum 小数位
	 * @return String
	 */
	public final static String getFormatValue(
			String _strValue,
			String _strFormat,
			String _strDecNum) {
		if (_strFormat.equals("财务数字")) {
			if (!_strDecNum.trim().equals("")) {
				_strValue =
						dotFormatForZero(_strValue, Integer.parseInt(_strDecNum));
			}
			_strValue = fnumber(_strValue);
		}
		if (_strFormat.equals("数字")) {
			if (!_strDecNum.trim().equals("")) {
				_strValue =
						dotFormatForZero(_strValue, Integer.parseInt(_strDecNum));
			}
		}
		if (_strFormat.equals("小时分钟")) {
			if (_strValue.equals(""))
				return "";
			int nhour = Integer.parseInt(_strValue);
			int nminute = nhour - ((int) nhour / 60) * 60;
			nhour = (int) nhour / 60;
			_strValue = "";
			if (nhour > 0) {
				_strValue = nhour + "小时";
			}
			if (nminute > 0) {
				_strValue += nminute + "分钟";
			}
		}
		if (_strFormat.equals("分钟秒")) {
			if (_strValue.equals(""))
				return "";
			int nhour = Integer.parseInt(_strValue);
			int nminute = nhour - ((int) nhour / 60) * 60;
			nhour = (int) nhour / 60;
			_strValue = "";
			if (nhour > 0) {
				_strValue = nhour + "分钟";
			}
			if (nminute > 0) {
				_strValue += nminute + "秒";
			}
		}

		return _strValue;
	}

	/**
	 * 提供精确的  加法  运算。
	 * @param v1 被加数
	 * @param v2 加数
	 * @param scale 表示表示需要精确到小数点以后几位。
	 * @param round 表示是否四舍五入 1表示是，0表示否。
	 * @return String 两个参数的和
	 */
	public final static String add(
			String v1,
			String v2,
			int scale,
			int round) {
		BigDecimal b1 = new BigDecimal(v1);
		BigDecimal b2 = new BigDecimal(v2);
		String caculate_result = (String) b1.add(b2).toString();
		BigDecimal one = new BigDecimal("1");
		BigDecimal caculate_result_big = new BigDecimal(caculate_result);

		if (round == 1) {
			caculate_result =
					caculate_result_big
							.divide(one, scale, BigDecimal.ROUND_HALF_UP)
							.toString();
		} else {
			caculate_result = dotFormat(caculate_result, scale);
		}
		return caculate_result;
	}

	/**
	 * 提供精确的  减法  运算。
	 * @param v1 被减数
	 * @param v2 减数
	 * @param scale 表示表示需要精确到小数点以后几位。
	 * @param round 表示是否四舍五入 1表示是，0表示否。
	 * @return String 两个参数的差
	 */
	public final static String sub(
			String v1,
			String v2,
			int scale,
			int round) {
		BigDecimal b1 = new BigDecimal(v1);
		BigDecimal b2 = new BigDecimal(v2);

		String caculate_result = (String) b1.subtract(b2).toString();
		BigDecimal one = new BigDecimal("1");
		BigDecimal caculate_result_big = new BigDecimal(caculate_result);

		if (round == 1) {
			caculate_result =
					caculate_result_big
							.divide(one, scale, BigDecimal.ROUND_HALF_UP)
							.toString();
		} else {
			caculate_result = dotFormat(caculate_result, scale);
		}
		return caculate_result;
	}

	/**
	 * 提供精确的  乘法  运算。
	 * @param v1 被乘数
	 * @param v2 乘数
	 * @param scale 表示表示需要精确到小数点以后几位。
	 * @param round 表示是否四舍五入 1表示是，0表示否。
	 * @return String 两个参数的积
	 */
	public final static String mul(
			String v1,
			String v2,
			int scale,
			int round) {
		BigDecimal b1 = new BigDecimal(v1);
		BigDecimal b2 = new BigDecimal(v2);

		String caculate_result = (String) b1.multiply(b2).toString();
		BigDecimal one = new BigDecimal("1");
		BigDecimal caculate_result_big = new BigDecimal(caculate_result);

		if (round == 1) {
			caculate_result =
					caculate_result_big
							.divide(one, scale, BigDecimal.ROUND_HALF_UP)
							.toString();
		} else {
			caculate_result = dotFormat(caculate_result, scale);
		}
		return caculate_result;
	}

	/**
	 * 提供（相对）精确的  除法  运算。当发生除不尽的情况时，由scale参数指
	 * 定精度，以后的数字四舍五入。
	 * @param v1 被除数
	 * @param v2 除数
	 * @param scale 表示表示需要精确到小数点以后几位。
	 * @param round 表示是否四舍五入 1表示是，0表示否。
	 * @return String 两个参数的商
	 */
	public final static String div(
			String v1,
			String v2,
			int scale,
			int round) {

		if (v2.equals("") || v2.equals("0")) {
			return "0";
		}

		if (scale < 0) {
			return v1;
		}
		BigDecimal b1 = new BigDecimal(v1);
		BigDecimal b2 = new BigDecimal(v2);

		String caculate_result =
				(String) b1.divide(b2, 10, BigDecimal.ROUND_HALF_UP).toString();
		if (round == 1) {
			caculate_result =
					b1.divide(b2, scale, BigDecimal.ROUND_HALF_UP).toString();
		} else {
			caculate_result = dotFormat(caculate_result, scale);
		}
		return caculate_result;
	}

	/**
	 * 提供精确的小数位  四舍五入  处理。
	 * @param v 需要四舍五入的数字
	 * @param scale 小数点后保留几位
	 * @return String 四舍五入后的结果
	 */
	public final static String round(String v, int scale) {
		if (scale < 0) {
			return v;
		}
		BigDecimal b = new BigDecimal(v);
		BigDecimal one = new BigDecimal("1");
		return b.divide(one, scale, BigDecimal.ROUND_HALF_UP).toString();
	}

	/**
	 * 数字转大写 (千万以内,不能为负  小数位不限
	 *             如果为 金额最多两位 到 分)
	 *
	 *  innumber -- 需 转 的数字
	 *    sign     -- 是否转为金额表示法 0－－不是金额 1－－是金额
	 * @return (String)         -- 转为大写的字符串
	 *
	 */
	public static final String converthz(double innumber, int sign) {
		if (innumber > 99999999.99) {
			return "数字过大!";
		}
		if (innumber < 0.00) {
			return "数字过小!";
		}
		if (java.lang.Math.abs(innumber) <= 0.001) {
			return "零";
		}
		if (sign == 0) {
			return converthz(innumber);
		} else {
			return converthzje(innumber);
		}
	}

	/**
	 * 数字转大写
	 * @param  innumber -- 需 转 的数字
	 * @return (String)          -- 转为大写的字符串
	 */
	public static final String converthz(double innumber) {
		String hzstr = "零壹贰叁肆伍陆柒捌玖";

		String numberdx = eString(innumber);

		String hz1 = "", hz2 = "", hz3 = "", shz2 = "";

		if (numberdx.indexOf(".") == -1) {
			hz1 = numberdx;
		} else {
			hz1 = numberdx.substring(0, numberdx.indexOf("."));
			hz2 =
					numberdx.substring(
							numberdx.indexOf(".") + 1,
							numberdx.length());
		}
		if (!hz1.equals("")) {
			if (hz1.length() >= 5) {
				hz3 = hz1.substring(0, hz1.length() - 4);
				hz1 = hz1.substring(hz1.length() - 4, hz1.length());
			}
		}
		for (int i = 0; i < hz2.length(); i++) {
			shz2 =
					shz2
							+ hzstr.substring(
							Integer.parseInt(hz2.substring(i, i + 1)),
							Integer.parseInt(hz2.substring(i, i + 1)) + 1);
		}

		if (hzconvert(shz2) == 0.0) {
			shz2 = "";
		}

		if (!shz2.trim().equals("")) {
			if (innumber < 1) {
				shz2 = "零点" + shz2;
			} else {
				shz2 = "点" + shz2;
			}
		}
		return makehz(hz3, "万", 1).trim()
				+ makehz(hz1, "", 1).trim()
				+ shz2.trim();
	}

	/**
	 * 将数字金额转为大写金额
	 *  数字金额
	 * @return String 大写金额
	 */
	public static final String converthzje(double innumber) {
		String hzstr = "零壹贰叁肆伍陆柒捌玖";

		String numberdx = eString(innumber);

		String hz1 = "", hz2 = "", hz3 = "", shz2 = "", rshz2 = "";

		if (numberdx.indexOf(".") == -1) {
			hz1 = numberdx;
		} else {
			hz1 = numberdx.substring(0, numberdx.indexOf("."));
			hz2 =
					numberdx.substring(
							numberdx.indexOf(".") + 1,
							numberdx.length());
		}

		if (Integer.valueOf(hz2).intValue() < 1) {
			hz2 = "";
		}
		if (hz2.startsWith("00")) {
			hz2 = "";
		}

		if (!hz1.equals("")) {
			if (hz1.length() >= 5) {
				hz3 = hz1.substring(0, hz1.length() - 4);
				hz1 = hz1.substring(hz1.length() - 4, hz1.length());
			}
		}

		for (int i = 0; i < hz2.length(); i++) {
			shz2 =
					shz2
							+ hzstr.substring(
							Integer.parseInt(hz2.substring(i, i + 1)),
							Integer.parseInt(hz2.substring(i, i + 1)) + 1);
		}
		if (hzconvert(shz2) == 0.0) {
			shz2 = "";
		} else {
			if (!shz2.substring(0, 1).equals("零")) {
				rshz2 = shz2.substring(0, 1) + "角";
			} else {
				rshz2 = shz2.substring(0, 1);
			}
			if ((shz2.length() > 1) && (!shz2.substring(1, 2).equals("零"))) {
				rshz2 = rshz2 + shz2.substring(1, 2) + "分";
			}
		}

		return makehz(hz3, "万", 0).trim()
				+ makehz(hz1, "元", 0).trim()
				+ rshz2.trim();
	}

	/**
	 * 大写转数字 (千万以内,不能为负  小数位位数不限
	 *              如果 表示金额 则小数位为两位 到 分)
	 *
	 *  instring -- 需 转 的大写字符串
	 * @return (double)          -- 转出的 数字 (双精度)  -1 --转换失败
	 *
	 */
	public static final double hzconvert(String instring) {
		try {
			return Double.parseDouble(instring);
		} catch (Exception e) {
		}

		instring = instring.trim();
		if (instring.equals("")
				|| instring.equals("零")
				|| instring.equals("零点零")
				|| instring.equals("零点零零")) {
			return 0;
		}
		if (instring.substring(0, 1).equals("拾")) {
			instring = "壹" + instring;
		}
		if ((instring.indexOf("元") != -1)
				|| (instring.indexOf("角") != -1)
				|| (instring.indexOf("分") != -1)) {
			if (!checkhzje(instring)) {
				return -1;
			}
			return hzjeconvert(instring);
		} else {
			if (!checkhz(instring)) {
				return -1;
			}
			return hzptconver(instring);
		}
	}

	private final static boolean checkhz(String instring) {
		String hzstr = "万千百拾点玖捌柒陆伍肆叁贰壹零";
		for (int i = 0; i < instring.length(); i++) {
			if (hzstr.indexOf(instring.substring(i, i + 1)) <= -1) {
				return false;
			}
		}
		return true;
	}

	/**
	 * 科学计数法的双精度数字转字符串
	 *
	 *  innumber -- 需转换的数字
	 * @return (String)          -- 转换后的字符串
	 *
	 */
	public static final String eString(double innumber) {
		if (innumber < 9999999.99) {
			return String.valueOf(innumber).trim();
		}
		double e = innumber / 100000;
		String ret = ForaddZero(9, String.valueOf(e));
		int uu = ret.indexOf(".");
		if (ret.length() > uu + 6) {
			ret =
					ret.substring(0, uu)
							+ ret.substring(uu + 1, uu + 6)
							+ "."
							+ ret.substring(uu + 6, ret.length());
		} else {
			ret = ret.substring(0, uu) + ret.substring(uu + 1, uu + 6);
		}
		return ret;
	}

	/**
	 * 科学计数法的浮点数字转字符串
	 *
	 *   innumber -- 需转换的数字
	 * @return (String)          -- 转换后的字符串
	 *
	 */
	public final static String eString(float innumber) {
		if (innumber < 9999999.99) {
			return String.valueOf(innumber).trim();
		}
		float e = innumber / 100000;
		String ret = ForaddZero(9, String.valueOf(e));
		int uu = ret.indexOf(".");
		if (ret.length() > uu + 6) {
			ret =
					ret.substring(0, uu)
							+ ret.substring(uu + 1, uu + 6)
							+ "."
							+ ret.substring(uu + 6, ret.length());
		} else {
			ret = ret.substring(0, uu) + ret.substring(uu + 1, uu + 6);
		}
		return ret;
	}

	private final static String makehz(String hzstr, String hzend, int sign) {
		String thz = "", shz = "", hzloc = "";
		int zerosign = 0;
		String hzchk = "零壹贰叁肆伍陆柒捌玖";
		for (int i = 0; i < hzstr.length(); i++) {
			shz =
					shz
							+ hzchk.substring(
							Integer.parseInt(hzstr.substring(i, i + 1)),
							Integer.parseInt(hzstr.substring(i, i + 1)) + 1);
		}
		hzloc = convertloc(hzstr, sign);
		for (int i = 0; i < shz.length(); i++) {
			thz = thz + shz.substring(i, i + 1);
			if (shz.substring(i, i + 1).equalsIgnoreCase("零")) {
				zerosign = 1;
			} else {
				zerosign = 0;
			}
			if (zerosign != 1) {
				thz = thz + hzloc.substring(i, i + 1);
			}
		}
		for (int i = 0; i < thz.length(); i++) {
			if (thz.indexOf("零零") != -1) {
				thz =
						thz.substring(0, thz.indexOf("零零"))
								+ thz.substring(thz.indexOf("零零") + 1, thz.length());
			}
		}
		for (int i = 0; i < thz.length(); i++) {
			if (thz.endsWith("零")) {
				thz = thz.substring(0, thz.length() - 1);
			}
		}
		if (thz.equals("零")) {
			thz = "";
		}
		if (thz.trim().equals("")) {
			return thz.trim();
		} else {
			return (thz.trim() + hzend).trim();
		}
	}

	private final static String subRealStr(String instring, int n) {
		instring = instring.trim();
		String realasc =
				"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789@#$%^&*()-_+./';:{}[]|\\=?><>`!";
		String rstr = "";
		int p = 0;
		for (int i = 0; i < instring.length(); i++) {
			rstr += instring.substring(i, i + 1);
			if (realasc.indexOf(instring.substring(i, i + 1)) > -1) {
				p++;
			} else {
				p += 2;
			}
			if (p >= n) {
				return rstr;
			}
		}
		return instring;
	}

	private final static String convertloc(String shz, int sign) {
		if (sign == 1) { //数字
			switch (shz.length()) {
				case 1 :
					return " ";
				case 2 :
					return "拾 ";
				case 3 :
					return "百拾 ";
				case 4 :
					return "千百拾 ";
			}
		} else { //金额
			switch (shz.length()) {
				case 1 :
					return " ";
				case 2 :
					return "拾 ";
				case 3 :
					return "佰拾 ";
				case 4 :
					return "仟佰拾 ";
			}
		}
		return " ";
	}

	private final static boolean checkhzje(String instring) {
		String hzstr = "万仟佰拾元角分玖捌柒陆伍肆叁贰壹零";
		for (int i = 0; i < instring.length() - 1; i++) {
			if (hzstr.indexOf(instring.substring(i, i + 1)) <= -1) {
				return false;
			}
		}
		if ((instring.indexOf("角") > 2) && (instring.indexOf("元") == -1)) {
			return false;
		}
		if ((instring.indexOf("分") > 4) && (instring.indexOf("元") == -1)) {
			return false;
		}
		if ((instring.indexOf("分") > 2)
				&& (instring.indexOf("元") == -1)
				&& (instring.indexOf("角") == -1)) {
			return false;
		}

		return true;
	}

	/**
	 * 字符串后补零
	 *  weishu   －补0后的总位数
	 * num    --需补零的字符串
	 * @return (String)       --补零后的字符串
	 */
	public static final String ForaddZero(int weishu, String num) {
		int len = num.length();
		if (len >= weishu) {
			return num;
		}
		int i = 0;
		int j = weishu - len;
		String BH = "";
		while (i < j) {
			BH = BH + "0";
			i = i + 1;
		}
		BH = num + BH;
		return BH;
	}

	/**
	 * 得到当前日期
	 * @return (String) 当前日期
	 */
	public final static String getDate() {
		java.text.SimpleDateFormat d = new java.text.SimpleDateFormat();
		d.applyPattern("yyyy-MM-dd");
		java.util.Date nowdate = new java.util.Date();
		String str_date = d.format(nowdate);
		return str_date;
	}

	/**
	 * 得到当前日期时间
	 * @return (String) 当前日期时间
	 */
	public final static String getDatetime() {
		java.text.SimpleDateFormat d = new java.text.SimpleDateFormat();
		d.applyPattern("yyyy-MM-dd hh:mm:ss");
		java.util.Date nowdate = new java.util.Date();
		String str_date = getDate() + " " + getTime();
		return str_date;
	}

	/**
	 * 合并字符串，得到当前日期时间
	 * @param : String 日期字符串
	 * @param : String 时间字符串
	 * @return (String) 当前日期时间
	 */
	public final static String getDatetime(String sdate, String stime) {
		if (sdate.equals("") || stime.equals("")) {
			return "";
		}
		String strDate = tostanddate(sdate);
		if (!isDate(strDate)) {
			return "";
		}
		if (stime.indexOf(".") > 0) {
			return strDate + "-" + stime;
		} else {
			return strDate + " " + stime;
		}
	}

	/**
	 * 返回当前年份
	 * @return (String) 当前年份，四位
	 */
	public final static String getYear() {
		return getDate().substring(0, 4);
	}
	/**
	 * 返回指定年份/月份 所在的年份
	 * @return (String) 年份，四位
	 */
	public final static String getBefYear(String year, String month) {
		if (month.equals("1") || month.equals("01")) {
			int i = new Integer(year).intValue();
			i--;
			return String.valueOf(i);
		} else {
			return year;
		}
	}
	/**
	 * 返回当前季度
	 * @return (String) 当前季度，1位  1/2/3/4
	 */
	public final static String getSeason() {
		String sNowMonth = getShortMonth();
		if (sNowMonth.equals("4")
				|| sNowMonth.equals("5")
				|| sNowMonth.equals("6")) {
			return "2";
		}
		if (sNowMonth.equals("7")
				|| sNowMonth.equals("8")
				|| sNowMonth.equals("9")) {
			return "3";
		}
		if (sNowMonth.equals("10")
				|| sNowMonth.equals("11")
				|| sNowMonth.equals("12")) {
			return "4";
		}

		return "1";
	}
	/*
	 * 返回指定月份所在季度
	 *  月份 1/2..12
	 * @return (String) 当前季度，1位  1/2/3/4
	 */
	public final static String getSeason(String month) {
		String sNowMonth = getShortMonth();
		if (sNowMonth.equals("4")
				|| sNowMonth.equals("5")
				|| sNowMonth.equals("6")) {
			return "2";
		}
		if (sNowMonth.equals("04")
				|| sNowMonth.equals("05")
				|| sNowMonth.equals("06")) {
			return "2";
		}
		if (sNowMonth.equals("7")
				|| sNowMonth.equals("8")
				|| sNowMonth.equals("9")) {
			return "3";
		}
		if (sNowMonth.equals("07")
				|| sNowMonth.equals("08")
				|| sNowMonth.equals("09")) {
			return "3";
		}
		if (sNowMonth.equals("10")
				|| sNowMonth.equals("11")
				|| sNowMonth.equals("12")) {
			return "4";
		}

		return "1";
	}
	/*
	 * 返回当前季度(汉字)
	 * @return (String) 当前季度，3位  x季度
	 */
	public final static String getCSeason() {
		String sSeason = getSeason();
		if (sSeason.equals("1"))
			return "一季度";
		if (sSeason.equals("2"))
			return "二季度";
		if (sSeason.equals("3"))
			return "三季度";
		return "四季度";
	}
	/*
	 * 返回季度(汉字)
	 *  1/2/3/4
	 * @return (String) 当前季度，3位  x季度
	 */
	public final static String getCSeason(String sSeason) {
		if (sSeason.equals("1"))
			return "一季度";
		if (sSeason.equals("2"))
			return "二季度";
		if (sSeason.equals("3"))
			return "三季度";
		return "四季度";
	}
	/*
	 * 返回月份(汉字)
	 *  1/2/3/4
	 * @return (String) 当前月份 一月/二月....
	 */
	public final static String getCMonth(String sMonth) {
		if (sMonth.equals("1"))
			return "一月";
		if (sMonth.equals("2"))
			return "二月";
		if (sMonth.equals("3"))
			return "三月";
		if (sMonth.equals("4"))
			return "四月";
		if (sMonth.equals("5"))
			return "五月";
		if (sMonth.equals("6"))
			return "六月";
		if (sMonth.equals("7"))
			return "七月";
		if (sMonth.equals("8"))
			return "八月";
		if (sMonth.equals("9"))
			return "九月";
		if (sMonth.equals("10"))
			return "十月";
		if (sMonth.equals("11"))
			return "十一月";
		return "十二月";
	}

	/*
	 * 返回下一年
	 * @return (String) 下一年，四位
	 */
	public final static String getNextYear() {

		int i = new Integer(getDate().substring(0, 4)).intValue();
		i++;
		return "" + i;
	}

	/*
	 * 返回当前月份
	 * @return (String) 当前月份，两位
	 */
	public final static String getMonth() {
		return getDate().substring(5, 7);
	}

	/*
	 * 返回当前简略月份
	 * @return (String) 当前月份，1-2位
	 */
	public final static String getShortMonth() {
		String nowmonth = getDate().substring(5, 7);
		if (nowmonth.startsWith("0")) {
			return getDate().substring(6, 7);
		} else {
			return getDate().substring(5, 7);
		}
	}

	/*
	 * 返回当前月份得上个月份
	 *
	 * @return (String) 当前月份，两位
	 *
	 */
	public final static String getBefMonth() {
		int i = new Integer(getDate().substring(5, 7)).intValue();
		if (i > 1) {
			i--;
		} else {
			i = 12;
		}
		return "" + i;
	}

	/*
	 * 将当前时间字符串增加月份(必须为 yyyy-mm-dd 形式).
	 *
	 * @param movemonth 增加的月份   负值为减少月份.
	 * @return --转换后的时间字符串.str格式不对返回"".
	 *
	 */
	public static final String stringMoveMonth(int movemonth) {
		return stringMoveMonth(getDate(), movemonth);
	}

	/*
	 * 返回当前月份的下个月份
	 * @return (String) 当前月份，两位
	 */
	public final static String getNextMonth() {
		int i = new Integer(getDate().substring(5, 7)).intValue();
		if (i < 12) {
			i++;
		} else {
			i = 1;
		}
		return "" + i;
	}

	/*
	 * 得到当前日 字符串
	 * @return String
	 */
	public final static String getDay() {
		return getDate().substring(8, 10);
	}
	/*
	 * 得到当前日 字符串
	 * @return String
	 */
	public final static String getShortDay() {
		String nowday = getDate().substring(8, 10);
		if (nowday.startsWith("0")) {
			return getDate().substring(9, 10);
		} else {
			return getDate().substring(8, 10);
		}
	}
	/*
	 * 得到当前时间 字符串
	 * @return String
	 */
	public final static String getTime() {

		java.util.Date date = new java.util.Date();
		java.sql.Time time;
		time = new Time(date.getTime());
		String strTime = time.toString();

		return strTime;
	}

	/*
	 * 得到当前时间 字符串(不带秒)
	 * @return String
	 */
	public final static String getTimeNoSecond() {

		java.util.Date date = new java.util.Date();
		java.sql.Time time;
		time = new Time(date.getTime());
		String strTime = time.toString();

		return strTime.substring(0, 5);
	}

	/*
	 * 格式化 标准含时分秒的字符串
	 * @param : String 时间字符串
	 * @return: String
	 */
	public final static String getFullTime(String stime) {
		if (stime.equals("")) {
			return "";
		}
		String strTime = stime;
		if (strTime.indexOf(".") > 0) {
			return strTime + ".00";
		} else {
			return strTime + ":00";
		}
	}

	/*
	 * 得到当前小时字符串
	 * @return String
	 */
	public final static String getHour() {
		return getTime().substring(0, 2);
	}

	/*
	 * 得到当前分钟字符串
	 * @return String
	 */
	public final static String getMinute() {
		return getTime().substring(3, 5);
	}

	/*
	 * 得到当前秒钟字符串
	 * @return String
	 */
	public final static String getSecond() {
		return getTime().substring(6, 8);
	}

	/*
	 * 得到目前日期星期数
	 * @return (String) 星期N
	 */
	public final static String thisweek() {
		int weekday = thisweekNum();
		if (weekday == 0) {
			return "星期日";
		}
		if (weekday == 1) {
			return "星期一";
		}
		if (weekday == 2) {
			return "星期二";
		}
		if (weekday == 3) {
			return "星期三";
		}
		if (weekday == 4) {
			return "星期四";
		}
		if (weekday == 5) {
			return "星期五";
		}
		if (weekday == 6) {
			return "星期六";
		}
		return "";
	}
	/*
	 * 得到目前日期星期数
	 * @return (int) 0-6
	 */
	public final static int thisweekNum() {
		java.text.SimpleDateFormat d = new java.text.SimpleDateFormat();
		d.applyPattern("yyyy-MM-dd");
		java.util.Date today = new java.util.Date();

		return today.getDay();
	}
	/*
	 * 得到特定日期字符串的星期数
	 * @return (int) 0-6
	 */
	public final static int getWeekNum(String rqstr) {
		java.util.Date today = stringToDate(rqstr);

		return today.getDay();
	}
	/*
	 * 得到特定日期字符串的星期数
	 * @return (String) 星期N
	 */
	public final static String getWeek(String rqstr) {
		int weekday = getWeekNum(rqstr);
		if (weekday == 0) {
			return "星期日";
		}
		if (weekday == 1) {
			return "星期一";
		}
		if (weekday == 2) {
			return "星期二";
		}
		if (weekday == 3) {
			return "星期三";
		}
		if (weekday == 4) {
			return "星期四";
		}
		if (weekday == 5) {
			return "星期五";
		}
		if (weekday == 6) {
			return "星期六";
		}
		return "";
	}
	/*
	 * 得到目前日期的月份值
	 * @return (String)
	 */
	public final static String thismonth() {
		java.text.SimpleDateFormat d = new java.text.SimpleDateFormat();
		d.applyPattern("yyyy-MM-dd");
		java.util.Date today = new java.util.Date();
		String str_date = d.format(today);
		int firstDash = str_date.indexOf('-');
		int secondDash = str_date.indexOf('-', firstDash + 1);
		str_date = str_date.substring(0, secondDash + 1) + "01";
		return str_date;
	}

	/*
	 * 得到目前日期的季度值
	 * @return (String)
	 */
	public final static String thisseason() {
		java.text.SimpleDateFormat d = new java.text.SimpleDateFormat();
		d.applyPattern("yyyy-MM-dd");
		java.util.Date today = new java.util.Date();
		int month = Integer.parseInt(getDate().substring(5, 7));
		String str_date = d.format(today);
		int firstDash = str_date.indexOf('-');
		if (month < 3) {
			str_date = str_date.substring(0, firstDash + 1) + "01-01";
		}
		if ((3 <= month) & (month < 6)) {
			str_date = str_date.substring(0, firstDash + 1) + "04-01";
		}
		if ((6 <= month) & (month < 9)) {
			str_date = str_date.substring(0, firstDash + 1) + "07-01";
		}
		if (9 <= month) {
			str_date = str_date.substring(0, firstDash + 1) + "10-01";
		}
		return str_date;
	}

	/*
	 * 得到当前月份的最后一天.
	 * @return (String)  lastday.
	 */
	public static final String getNowLastDay() {
		return getLastDay(getDate());
	}
	/*
	 * 得到当前月份的最后一天.
	 * @return (String)  lastday.
	 */
	public static final String getNowLastDay(String year, String month) {
		int month1 = Integer.parseInt(month);
		if (month1 < 10) {
			month = "0" + (month1);
		}
		return getLastDay(year + "-" + month + "-" + "01");
	}

	/*
	 * 得到当前月份的第一天.
	 * @return (String)  firstday.
	 */
	public static final String getNowFirDay() {
		return getFirDay(getDate());
	}
	/*
	 * 得到当前月份的第一天.
	 * @return (String)  firstday.
	 */
	public static final String getNowFirDay(String year, String month) {
		int month1 = Integer.parseInt(month);
		if (month1 < 10) {
			month = "0" + (month1);
		}

		return year + "-" + month + "-" + "01";
	}
	/*
	 * 得到某个日期所在月份的第一天.
	 *   date.
	 * @return (String)  lastday.
	 */
	public static final String getFirDay(String strFirDay) {
		strFirDay = tostanddate(strFirDay).substring(0, 8) + "01";
		return strFirDay;
	}

	/*
	 * 得到某个日期所在月份的最后一天.
	 *   date.
	 * @return (String)  lastday.
	 */
	public static final String getLastDay(String oldday) {
		oldday = tostanddate(oldday);
		if (!isDate(oldday)) {
			return "error";
		}
		int y = Integer.parseInt(oldday.substring(0, 4));
		int m = Integer.parseInt(oldday.substring(5, 7));
		int d = Integer.parseInt(oldday.substring(8, 10));

		switch (m) {
			case 2 :
				if (isLeap(y)) {
					d = 29;
				} else {
					d = 28;
				};
				break;
			case 4 :
			case 6 :
			case 9 :
			case 11 :
				d = 30;
				break;
			default :
				d = 31;
		}
		return oldday.substring(0, 8) + String.valueOf(d);
	}

	/*
	 * 判断是否为闰年
	 * @param  : int 年份
	 * @return : boolean-- true/false
	 */
	public static boolean isLeap(int y) {
		if (((y % 4 == 0) && (y % 100 != 0)) || (y % 400 == 0)) {
			return true; //是闰年;
		} else {
			return false;
		}
	}

	/*
	 * 得到某个月的实际天数
	 *
	 *  year  年份
	 *  month 月份
	 * @return days   该月实际天数
	 *
	 */
	public static final int getDays(String year, String month) {
		int y = Integer.parseInt(year);
		int m = Integer.parseInt(month);
		switch (m) {
			case 2 :
				if (isLeap(y)) {
					return 29;
				} else {
					return 28;
				}
			case 4 :
			case 6 :
			case 9 :
			case 11 :
				return 30;
			default :
				return 31;
		}
	}

	/*
	 * 得到当前月的实际天数
	 *
	 * @return days   该月实际天数
	 *
	 */
	public static final int getNowDays() {
		int y = Integer.parseInt(getYear());
		int m = Integer.parseInt(getMonth());
		switch (m) {
			case 2 :
				if (isLeap(y)) {
					return 29;
				} else {
					return 28;
				}
			case 4 :
			case 6 :
			case 9 :
			case 11 :
				return 30;
			default :
				return 31;
		}
	}
	/*
	 * 得到时间差异
	 *  indate1 -- 时间或时间戳 的字符串
	 *  indate2 -- 需校验的数字字符串
	 * @return (int)    时间差异值
	 */
	//返回年的差异 (与当前时间比较)
	public final static int getDyear(String indate1) {
		if (indate1.trim().length() < 4) {
			return 0;
		}
		indate1 = indate1.substring(0, 4);
		int nowdate = Integer.valueOf(getYear()).intValue();
		int ind = Integer.valueOf(indate1.substring(0, 4)).intValue();
		return nowdate - ind + 1;
	}

	//返回日的差异 (与当前时间比较)
	public final static int getDday(String indate1) {
		java.util.Date nowdate = new java.util.Date();
		int newday = nowdate.compareTo(stringToTime(indate1));
		return newday;
	}

	/*
	 * 返回两个日期的差异天数
	 * @param str 代表时间的字符串.（前一个值）
	 * @param str 代表时间的字符串.（后一个值）
	 *
	 * @return （int）--两个日期的差异天数（后 - 前）.
	 */
	public static final int getDDate(String strbef, String strlas) {
		if (strbef.trim().equals("") || strlas.trim().equals("")) {
			return 0;
		}
		if (!isDate(strbef)) {
			return 0;
		}
		if (!isDate(strbef)) {
			return 0;
		}
		strbef = tostanddate(strbef);
		strlas = tostanddate(strlas);

		int ny1 = Integer.parseInt(strbef.substring(0, 4));
		int nm1 = Integer.parseInt(strbef.substring(5, 7));
		int nd1 = Integer.parseInt(strbef.substring(8, 10));

		int ny2 = Integer.parseInt(strlas.substring(0, 4));
		int nm2 = Integer.parseInt(strlas.substring(5, 7));
		int nd2 = Integer.parseInt(strlas.substring(8, 10));

		int nDiffDay = 0;
		int nBefDay = 0;
		int nLasDay = 0;

		nBefDay = ny1 * 365 + (int) nBefDay / 4 + nd1 + getMonthDay(ny1, nm1);

		nLasDay = ny2 * 365 + (int) nLasDay / 4 + nd2 + getMonthDay(ny2, nm2);

		return nLasDay - nBefDay;
	}

	private final static int getMonthDay(int nYear, int nMonth) {

		int nBefDay = 0;
		if (nMonth == 2) {
			nBefDay = nBefDay + 31;
		}
		if (nMonth == 3) {
			if (isLeap(nYear)) {
				nBefDay = nBefDay + 31 + 29;
			} else {
				nBefDay = nBefDay + 31 + 28;
			}
		}
		if (nMonth == 4) {
			if (isLeap(nYear)) {
				nBefDay = nBefDay + 31 + 29 + 31;
			} else {
				nBefDay = nBefDay + 31 + 28 + 31;
			}
		}
		if (nMonth == 5) {
			if (isLeap(nYear)) {
				nBefDay = nBefDay + 31 + 29 + 31 + 30;
			} else {
				nBefDay = nBefDay + 31 + 28 + 31 + 30;
			}
		}
		if (nMonth == 6) {
			if (isLeap(nYear)) {
				nBefDay = nBefDay + 31 + 29 + 31 + 30 + 31;
			} else {
				nBefDay = nBefDay + 31 + 28 + 31 + 30 + 31;
			}
		}
		if (nMonth == 7) {
			if (isLeap(nYear)) {
				nBefDay = nBefDay + 31 + 29 + 31 + 30 + 31 + 30;
			} else {
				nBefDay = nBefDay + 31 + 28 + 31 + 30 + 31 + 30;
			}
		}
		if (nMonth == 8) {
			if (isLeap(nYear)) {
				nBefDay = nBefDay + 31 + 29 + 31 + 30 + 31 + 30 + 31;
			} else {
				nBefDay = nBefDay + 31 + 28 + 31 + 30 + 31 + 30 + 31;
			}
		}
		if (nMonth == 9) {
			if (isLeap(nYear)) {
				nBefDay = nBefDay + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31;
			} else {
				nBefDay = nBefDay + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31;
			}
		}
		if (nMonth == 10) {
			if (isLeap(nYear)) {
				nBefDay = nBefDay + 31 + 29 + 31 + 30 + 31 + 31 + 30 + 31 + 30;
			} else {
				nBefDay = nBefDay + 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30;
			}
		}
		if (nMonth == 11) {
			if (isLeap(nYear)) {
				nBefDay =
						nBefDay + 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31;
			} else {
				nBefDay =
						nBefDay + 31 + 28 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31;
			}
		}
		if (nMonth == 12) {
			if (isLeap(nYear)) {
				nBefDay =
						nBefDay
								+ 31
								+ 29
								+ 31
								+ 30
								+ 31
								+ 30
								+ 31
								+ 31
								+ 30
								+ 31
								+ 30;
			} else {
				nBefDay =
						nBefDay
								+ 31
								+ 28
								+ 31
								+ 30
								+ 31
								+ 30
								+ 31
								+ 31
								+ 30
								+ 31
								+ 30;
			}
		}
		return nBefDay;
	}

	//返回月份差异   (indate2 为 月份差异   indate1 必须为 YYYY-MM-DD 格式 注意：只能返回正确的年 和 月)
	public final static String getNmon(String indate1, int indate2) {
		return stringMoveMonth(indate1.substring(0, 10), indate2);
	}

	//返回月份差异  （与当前时间比较）
	public final static String getNmon(int indate2) {
		return getNmon(getDate(), indate2);
	}

	/*
	 * 得到当前日期的前一天
	 * @return (String) 新的时间字符串
	 */
	public final static String getBefDay() {
		return getBefDay(getDate());
	}
	/*
	 * 得到当前日期的后一天
	 * @return (String) 新的时间字符串
	 */
	public final static String getNextDay() {
		return getDate(1, getDate(), "");
	}

	/**
	 * 得到离传入日期的 第 DAYS 天的新日期
	 *
	 *  days  取某一天前 days = 负数, 某一天后 days = 正数 天
	 * @param  strDate 传入的日期字符串
	 * @param format 固定为空串:"" 为标准格式
	 */
	public final static String getDate(
			int days,
			String strDate,
			String format) {
		format = "yyyy-MM-dd";
		if (strDate == null || strDate.equals("")) {
			strDate = getDate();
		}

		SimpleDateFormat formatter = new SimpleDateFormat(format);
		Date date = null;
		try {
			date = formatter.parse(strDate);
		} catch (ParseException e) {
			date = new Date();
		}

		if (days == 0) {
			return formatter.format(date);
		} else {
			Calendar nowdate = Calendar.getInstance();
			nowdate.setTime(date);
			nowdate.add(Calendar.DAY_OF_YEAR, days);

			return formatter.format(nowdate.getTime());
		}
	}

	/**
	 * 得到传入时间的累计秒数
	 *
	 * @return (float) 累计秒数
	 *
	 */
	public final static float getTotSecond(String sInDate) {
		float totsec = 0;
		String temp = "";
		temp = sInDate.substring(10, 12);
		totsec = Float.parseFloat(temp) * 60 * 60;
		temp = sInDate.substring(13, 15);
		totsec += Float.parseFloat(temp) * 60;

		temp = sInDate.substring(16);
		totsec += Float.parseFloat(temp);

		return totsec;
	}

	/*
	 * 得到指定日期的前一天
	 *  指定日期
	 * @return String
	 */
	public final static String getBefDay(String indate) {
		indate = indate.trim();
		if (indate.substring(4, 5).equals("-")
				&& indate.substring(6, 7).equals("-")) {
			indate = indate.substring(0, 5) + "0" + indate.substring(5);
		}
		if (indate.length() < 10) {
			indate = indate.substring(0, 8) + "0" + indate.substring(8);
		}

		int year = Integer.valueOf(indate.substring(0, 4)).intValue();
		int month = Integer.valueOf(indate.substring(5, 7)).intValue();
		int day = Integer.valueOf(indate.substring(8, 10)).intValue();

		if (day == 1 && month == 1) {
			return String.valueOf(year - 1) + "-12-31";
		}

		if (day == 1 && month > 1) {
			if (month == 5 || month == 7 || month == 10 || month == 12) {
				day = 30;
			}
			if (month == 8
					|| month == 2
					|| month == 4
					|| month == 6
					|| month == 9
					|| month == 11) {
				day = 31;
			}
			if (month == 3) {
				if (isLeap(year)) {
					day = 29;
				} else {
					day = 28;
				}
			}
			month--;
			return (indate.substring(0, 5))
					+ (month > 9
					? String.valueOf(month)
					: "0" + String.valueOf(month))
					+ "-"
					+ String.valueOf(day);
		}

		return (indate.substring(0, 8))
				+ (day > 10
				? String.valueOf(day - 1)
				: "0" + String.valueOf(day - 1));
	}

	//检查年月日是否合法
	private final static boolean isCalender(int y, int m, int d) {
		//时间值越界；
		if ((y < 1900) || (y > 4712)) {
			return false;
		}
		if ((m < 1) || (m > 12)) {
			return false;
		}
		if ((d < 1) || (d > 31)) {
			return false;
		}
		//判断天是否正确
		switch (m) {
			case 2 :
				if (isLeap(y)) {
					if (d > 29) {
						return false;
					}
				} else {
					if (d > 28) {
						return false;
					}
				};
				break;
			case 4 :
			case 6 :
			case 9 :
			case 11 :
				if (d > 30) {
					return false;
				}
				break;
			default :
				return true;
		}
		return true;
	}

	/*
	 * 将字符串转换为时间.
	 * @param str 代表时间的字符串.
	 * @return --转换后的时间.str格式不对返回null.
	 */
	public static final java.sql.Timestamp stringToTime(String str) {
		if (str == null) {
			return null;
		}
		str = str.trim();
		java.text.SimpleDateFormat formatter =
				new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		java.util.Date tDate = null;
		try {
			tDate = formatter.parse(str);
		} catch (Exception e) {
		}
		if (tDate == null && str.indexOf(' ') < 0) {
			formatter = new java.text.SimpleDateFormat("yyyy-MM-dd");
			try {
				tDate = formatter.parse(str);
			} catch (Exception e) {
			}
		}
		if (tDate == null) {
			return null;
		}
		java.sql.Timestamp timeStame = new java.sql.Timestamp(tDate.getTime());
		return timeStame;
	}

	/*
	 * 检查日期的相关值合法性.(三个之中有空值则不校验)
	 *
	 * year  年 4位
	 * month 月 2位
	 * day   日 2位.
	 *
	 * @return (boolean)  true 合法  false 不合法.
	 *
	 */
	public static final boolean isDate(String year, String month, String day) {
		if (year.trim().length() == 0
				|| month.trim().length() == 0
				|| day.trim().length() == 0) {
			return true;
		}
		int y, m, d;
		try {
			y = Integer.parseInt(year);
			m = Integer.parseInt(month);
			d = Integer.parseInt(day);
		} catch (NumberFormatException e) {
			return false;
		}
		return isCalender(y, m, d);
	}

	/*
	 * 检查日期的相关值合法性.(三个之中有空值则不校验)
	 *
	 * year 年 4位 (String)month (String)day.
	 * @param (允许最大日期) "nnnn-yy-mm" ,"0000-00-00" 不大于当前日期，"" 不校验
	 * @param (允许最小日期) "nnnn-yy-mm" ,"" 不校验
	 *
	 * @return (boolean)  true 合法  false 不合法.
	 *
	 */
	public static final boolean isDate(
			String year,
			String month,
			String day,
			String maxdate,
			String mindate) {
		if (!isDate(year, month, day)
				|| (!isDate(maxdate)
				&& !maxdate.equals("0000-00-00")
				&& !maxdate.trim().equals(""))
				|| (!isDate(mindate) && !mindate.trim().equals(""))) {
			return false;
		}

		if (maxdate.equals("0000-00-00")) {
			return (
					stringToTime(year + "-" + month + "-" + "01").before(
							new java.util.Date()));
		}
		if (!maxdate.trim().equals("")) {
			return (
					stringToTime(year + "-" + month + "-" + "01").before(
							stringToTime(maxdate)));
		}
		if (!mindate.trim().equals("")) {
			return (
					stringToTime(year + "-" + month + "-" + "01").after(
							stringToTime(mindate)));
		}

		return true;
	}

	/*
	 * 检查时间的相关值合法性.
	 *
	 * hour (String)minut (String)sec.
	 * @return (boolean)  true 合法  false 不合法.
	 *
	 */
	public static final boolean isTime(
			String hour,
			String minute,
			String secs) {
		int h, m, s;
		try {
			h = Integer.parseInt(hour);
			m = Integer.parseInt(minute);
			s = Integer.parseInt(secs);
		} catch (NumberFormatException e) {
			return false;
		}
		if (h < 0 || h > 23) {
			return false;
		}
		if (m < 0 || m > 59) {
			return false;
		}
		if (s < 0 || s > 59) {
			return false;
		}
		return true;
	}

	/*
	 * 根据输入的字符串解析出年月日和时分秒，并检查日期的有效性。
	 *
	 *   textStr --输入的字符串
	 * @return (boolean) true--成功   false--失败
	 *
	 */
	public static final boolean dateTextFieldParse(String textStr) {
		int index = textStr.indexOf(".");
		if (index > -1) {
			textStr = textStr.substring(0, index);
		}
		String year, month, day, hour, minute, second;
		int hypen1Index, hypen2Index, blankIndex, colon1Index, colon2Index;
		hypen1Index = textStr.indexOf("-");
		if (hypen1Index != -1) {
			hypen2Index = textStr.indexOf("-", hypen1Index + 1);
			if (hypen2Index != -1) {
				blankIndex = textStr.indexOf(" ");
				if (blankIndex != -1) {
					colon1Index = textStr.indexOf(":");
					if (colon1Index != -1) {
						colon2Index = textStr.indexOf(":", colon1Index + 1);
						if (colon2Index != -1) {
							//提取年月日和时分秒
							year = textStr.substring(0, hypen1Index);
							month =
									textStr.substring(hypen1Index + 1, hypen2Index);
							day =
									textStr.substring(hypen2Index + 1, blankIndex);
							hour =
									textStr.substring(blankIndex + 1, colon1Index);
							minute =
									textStr.substring(colon1Index + 1, colon2Index);
							second = textStr.substring(colon2Index + 1);
							if (isDate(year, month, day)) {
								if (isTime(hour, minute, second)) {
									return true;
								} else {
									return false;
								}
							} else {
								return false;
							}
						} else {
							return false;
						}
					} else {
						return false;
					}
				} else { //年月日
					year = textStr.substring(0, hypen1Index);
					month = textStr.substring(hypen1Index + 1, hypen2Index);
					day = textStr.substring(hypen2Index + 1);
					if (isDate(year, month, day)) {
						return true;
					} else {
						return false;
					}
				}
			} else {
				return false;
			}
		} else {
			return false;
		}
	}

	/*
	 * 将传入的日期字符串表达式格式化
	 * @param  : String 日期字符串
	 * @return : String
	 */
	public final static String tostanddate(String str) {
		str = str.trim();
		if (str.substring(6, 7).equals("-")) {
			str = str.substring(0, 5) + "0" + str.substring(5, str.length());
		}
		if (str.trim().length() < 10) {
			str = str.substring(0, 8) + "0" + str.substring(8, 9);
		}
		return str;
	}

	/*
	 * 获取日期字符串中的年字串
	 *  日期字符串
	 * @return String
	 */
	public final static String getYearStr(String sdate) {
		ArrayList d;
		d = datelist(sdate);
		if (d == null || d.isEmpty()) {
			return "";
		}
		if (d.size() < 3) {
			return "";
		}
		return (String) d.get(0);
	}

	/*
	 * 获取日期字符串中的月字串
	 *  日期字符串
	 * @return String
	 */
	public final static String getMonthStr(String sdate) {
		ArrayList d;
		d = datelist(sdate);
		if (d == null || d.isEmpty()) {
			return "";
		}
		if (d.size() < 3) {
			return "";
		}
		return (String) d.get(1);
	}
	/*
	 * 获取日期字符串中的月字串
	 *  日期字符串
	 * @return String
	 */
	public final static String getMonthStrs(String sdate) {
		ArrayList d;
		d = datelist(sdate);
		if (d == null || d.isEmpty()) {
			return "";
		}
		if (d.size() < 3) {
			return "";
		}
		String month = (String) d.get(1);

		if (month.startsWith("0"))
			month = month.substring(1);

		return month;
	}
	/*
	 * 得到日期字符串的 日 子串
	 * @param  : String 日期字符串
	 * @return : String 日 子串
	 */
	public final static String getDayStr(String sdate) {
		ArrayList d;
		d = datelist(sdate);
		if (d == null || d.isEmpty()) {
			return "";
		}
		if (d.size() < 3) {
			return "";
		}
		return (String) d.get(2);
	}

	/*
	 * 得到日期字符串的 日 子串
	 * @param  : String 日期字符串
	 * @return : String 日 子串 对于小于10的前面不加0
	 */
	public final static String getDayStrs(String sdate) {
		ArrayList d;
		d = datelist(sdate);
		if (d == null || d.isEmpty()) {
			return "";
		}
		if (d.size() < 3) {
			return "";
		}
		String day = (String) d.get(2);
		if (day.startsWith("0"))
			day = day.substring(1);
		return day;
	}

	private final static ArrayList datelist(String sdate) {
		if (sdate.trim().length() < 8 || sdate.trim().length() > 10) {
			return null;
		}
		String sd = tostanddate(sdate);
		if (!isDate(sd)) {
			return null;
		}
		ArrayList al = new ArrayList();
		al.add(sd.substring(0, 4));
		al.add(sd.substring(5, 7));
		al.add(sd.substring(8, 10));
		return al;
	}

	/*
	 * 将时间字符串增加月份(必须为 yyyy-mm-dd 形式).
	 * @param str 表示时间的字符串.
	 * @param movemonth 增加的月份   负值为减少月份.
	 * @return --转换后的时间字符串.str格式不对返回"".
	 */
	public static final String stringMoveMonth(String str, int movemonth) {
		if (!isDate(str)) {
			return "";
		}
		int year = Integer.parseInt(str.substring(0, 4));
		int month = Integer.parseInt(str.substring(5, 7));
		String dstr = str.substring(8);
		if (dstr.startsWith("0"))
			dstr = dstr.substring(1);

		int day = Integer.parseInt(dstr);

		int yeary = year;
		int monthy = month;
		int dayy = day;
		int moveyear = Math.abs(movemonth);
		moveyear = (int) (moveyear / 12);
		if (movemonth > 0) {
			year += moveyear;
		} else {
			year -= moveyear;
		}

		int passmonth =
				Math.abs(movemonth) - 12 * (int) ((Math.abs(movemonth)) / 12);

		if (passmonth > 0) {
			if (movemonth > 0) {
				if ((movemonth + month) > 12) {
					year++;
					month = movemonth + month - 12;
				} else {
					month = movemonth + month;
				}
			} else {
				if (month > Math.abs(movemonth)) {
					month -= Math.abs(movemonth);
				} else {
					year--;
					month = 12 + month + movemonth;
				}
			}
		}
		//---------------2007-7-3----
		if (month == 2) {
			if (dayy > 27) {
				int ydr =
						Integer.parseInt(getlastDays("" + yeary, "" + monthy));
				int xcts = ydr - dayy;
				if (xcts < 0)
					xcts = 0;
				day =
						Integer.parseInt(getlastDays("" + year, "" + month)) - xcts;
			}
		} else {
			if (dayy > 29) {
				int ydr =
						Integer.parseInt(getlastDays("" + yeary, "" + monthy));
				int xcts = ydr - dayy;
				if (xcts < 0)
					xcts = 0;
				day =
						Integer.parseInt(getlastDays("" + year, "" + month)) - xcts;
			}
		}
		//-------------------
		String daystr = (day > 9) ? "" + day : "0" + day;
		if (month > 9) {
			return String.valueOf(year)
					+ str.substring(4, 5)
					+ String.valueOf(month)
					+ "-"
					+ daystr;
		} else {
			return String.valueOf(year)
					+ str.substring(4, 5)
					+ "0"
					+ String.valueOf(month)
					+ "-"
					+ daystr;
		}
	}
	/*
	 * 将时间字符串增加月份(必须为 yyyy-mm-dd 形式).
	 * @param year,month,day
	 * @param movemonth 增加的月份   负值为减少月份.
	 * @return
	 */
	public static final String stringMoveMonth(
			int year,
			int month,
			int day,
			int movemonth) {

		int yeary = year;
		int monthy = month;
		int dayy = day;

		int moveyear = Math.abs(movemonth);
		moveyear = (int) (moveyear / 12);
		if (movemonth > 0) {
			year += moveyear;
		} else {
			year -= moveyear;
		}

		int passmonth =
				Math.abs(movemonth) - 12 * (int) ((Math.abs(movemonth)) / 12);

		if (passmonth > 0) {
			if (movemonth > 0) {
				if ((movemonth + month) > 12) {
					year++;
					month = movemonth + month - 12;
				} else {
					month = movemonth + month;
				}
			} else {
				if (month > Math.abs(movemonth)) {
					month -= Math.abs(movemonth);
				} else {
					year--;
					month = 12 + month + movemonth;
				}
			}
		}
		//---------------2007-7-3----
		if (month == 2) {
			if (dayy > 27) {
				int ydr =
						Integer.parseInt(getlastDays("" + yeary, "" + monthy));
				int xcts = ydr - dayy;
				if (xcts < 0)
					xcts = 0;
				day =
						Integer.parseInt(getlastDays("" + year, "" + month)) - xcts;
			}
		} else {
			if (dayy > 29) {
				int ydr =
						Integer.parseInt(getlastDays("" + yeary, "" + monthy));
				int xcts = ydr - dayy;
				if (xcts < 0)
					xcts = 0;
				day =
						Integer.parseInt(getlastDays("" + year, "" + month)) - xcts;
			}
		}
		//-------------------
		String daystr = (day > 9) ? "" + day : "0" + day;

		if (month > 9) {
			return String.valueOf(year)
					+ "-"
					+ String.valueOf(month)
					+ "-"
					+ daystr;
		} else {
			return String.valueOf(year)
					+ "-"
					+ "0"
					+ String.valueOf(month)
					+ "-"
					+ daystr;
		}
	}
	/*
		 * 将时间字符串增加月份(必须为 yyyy-mm-dd 形式).
		 * @param year,month,day
		 * @return --上一月日期
		 */
	public static final String stringupMonth(int y, int m, int d) {

		return stringMoveMonths(y, m, d, -1);

	}
	/*
	 * 将时间字符串增加月份(必须为 yyyy-mm-dd 形式).
	 * @param year,month,day
	 * @param movemonth 增加的月份   负值为减少月份.
	 * @return
	 */
	public static final String stringMoveMonths(
			int year,
			int month,
			int day,
			int movemonth) {

		int yeary = year;
		int monthy = month;
		int dayy = day;

		int moveyear = Math.abs(movemonth);
		moveyear = (int) (moveyear / 12);
		if (movemonth > 0) {
			year += moveyear;
		} else {
			year -= moveyear;
		}

		int passmonth =
				Math.abs(movemonth) - 12 * (int) ((Math.abs(movemonth)) / 12);

		if (passmonth > 0) {
			if (movemonth > 0) {
				if ((movemonth + month) > 12) {
					year++;
					month = movemonth + month - 12;
				} else {
					month = movemonth + month;
				}
			} else {
				if (month > Math.abs(movemonth)) {
					month -= Math.abs(movemonth);
				} else {
					year--;
					month = 12 + month + movemonth;
				}
			}
		}
		//---------------2007-7-3----
		if (month == 2) {
			if (dayy > 27) {
				int ydr =
						Integer.parseInt(getlastDays("" + yeary, "" + monthy));
				int xcts = ydr - dayy + 1;
				if (xcts < 0)
					xcts = 0;
				day =
						Integer.parseInt(getlastDays("" + year, "" + month)) - xcts;
			}
		} else {
			if (dayy > 29) {
				int ydr =
						Integer.parseInt(getlastDays("" + yeary, "" + monthy));
				int xcts = ydr - dayy + 1;
				if (xcts < 0)
					xcts = 0;
				day =
						Integer.parseInt(getlastDays("" + year, "" + month)) - xcts;
			} else {
				day++;
			}
		}
		//-------------------
		String daystr = (day > 9) ? "" + day : "0" + day;

		if (month > 9) {
			return String.valueOf(year)
					+ "-"
					+ String.valueOf(month)
					+ "-"
					+ daystr;
		} else {
			return String.valueOf(year)
					+ "-"
					+ "0"
					+ String.valueOf(month)
					+ "-"
					+ daystr;
		}
	}
	/*
	 * 是否为日期型字符串
	 * @param   需校验 的数据
	 * @return  boolean 校验后的结果
	 *          true--正确 false--错误
	 */
	public final static boolean isDate(String str) {
		try {
			if ((str == null) || (str.equals(""))) {
				return false;
			} else {
				str = str.trim();
			}
			java.sql.Date date = null;
			date = java.sql.Date.valueOf(str);
			//		if (!str.equals(date.toString())) {
			//			return false;
			//		}
			return true;
		} catch (Exception e) {
			return false;
		}
	}
	/*
	 * 得到某年某月的日
	 * @param: String 年
	 * @param: String 月
	 * @return: (String) 日
	 */
	public static final String getlastDays(String year, String month) {
		int nbegin = 1;
		int nend = 31;
		if (month.equals("2") || month.equals("02")) {
			if (isLeap(Integer.parseInt(year))) {
				nend = 29;
			} else {
				nend = 28;
			}
		}
		if (month.equals("1") || month.equals("01")) {
			nend = 31;
		}
		if (month.equals("3") || month.equals("03")) {
			nend = 31;
		}
		if (month.equals("4")
				|| month.equals("04")
				|| month.equals("6")
				|| month.equals("06")
				|| month.equals("9")
				|| month.equals("09")) {
			nend = 30;
		}
		if (month.equals("5")
				|| month.equals("05")
				|| month.equals("7")
				|| month.equals("07")
				|| month.equals("8")
				|| month.equals("08")) {
			nend = 31;
		}
		if (month.equals("10") || month.equals("12")) {
			nend = 31;
		}
		if (month.equals("11")) {
			nend = 30;
		}

		String strday = "";
		for (int n = nbegin; n <= nend; n++) {
			strday += n + "=" + n + ";";
		}
		return "" + nend;
	}
	/*
	 * 得到某年某月的所有日
	 * @param: String 年
	 * @param: String 月
	 * @return: (String) 所有日
	 */
	public static final String getAllDay(String year, String month) {
		int nbegin = 1;
		int nend = 31;
		if (month.equals("2") || month.equals("02")) {
			if (isLeap(Integer.parseInt(year))) {
				nend = 29;
			} else {
				nend = 28;
			}
		}
		if (month.equals("1") || month.equals("01")) {
			nend = 31;
		}
		if (month.equals("3") || month.equals("03")) {
			nend = 31;
		}
		if (month.equals("4")
				|| month.equals("04")
				|| month.equals("6")
				|| month.equals("06")
				|| month.equals("9")
				|| month.equals("09")) {
			nend = 30;
		}
		if (month.equals("5")
				|| month.equals("05")
				|| month.equals("7")
				|| month.equals("07")
				|| month.equals("8")
				|| month.equals("08")) {
			nend = 31;
		}
		if (month.equals("10") || month.equals("12")) {
			nend = 31;
		}
		if (month.equals("11")) {
			nend = 30;
		}

		String strday = "";
		for (int n = nbegin; n <= nend; n++) {
			strday += n + "=" + n + ";";
		}
		return strday.substring(0, strday.length() - 1);
	}

	/*
	 * 得到当前日期的前一个月所在年
	 * @return: (String)年
	 */
	public static final String getBefYear() {
		if (getMonth().equals("01") || getMonth().equals("1")) {
			return String.valueOf(Integer.parseInt(getYear()) - 1);
		} else {
			return getYear();
		}
	}
	/*
	 * 得到当前日期前1年所在年
	 * @return: (String)年
	 */
	public static final String getBYear() {
		return String.valueOf(Integer.parseInt(getYear()) - 1);
	}

	/*
	 * 得到1年的所有月份字符串，用于下拉框
	 * @return: (String)年
	 */
	public static final String getAllMonth() {
		return "1=1;2=2;3=3;4=4;5=5;6=6;7=7;8=8;9=9;10=10;11=11;12=12";
	}

	/*
	 * 得到1年的所有月份字符串，用于映射下拉框,显示大写 ，值为小写
	 * @return: (String)年
	 */
	public static final String getAllMonthS() {
		return "一月份=1;二月份=2;三月份=3;四月份=4;五月份=5;六月份=6;七月份=7;八月份=8;九月份=9;十月份=10;十一月份=11;十二月份=12";
	}

	/*
	 * 得到某一年的前N年
	 * @param : String year 某年
	 * @param : int n  前N年
	 * @return: (String)第N年
	 */
	public static final String getBefYear(String year, int n) {
		return String.valueOf(Integer.parseInt(year) - n);
	}

	/*
	 * 得到当年的第一天
	 * return:(String)当年的第一天
	 */
	public static final String getFirstDayOfYear() {
		return getYear() + "-" + getMonth() + "-01";
	}

	/*
	 * 得到当前年的前N年的字符串 （含当前年，用 ；隔开，主要用于下拉框）
	 * @param : int 前N年
	 * @param : String 前N年的字符串
	 */
	public static final String getAllYear(int n) {
		String nyearlist = "";
		int nyear = Integer.parseInt(getYear());
		for (int t = 0; t < n; t++) {
			nyearlist += (nyear - t) + ";";
		}
		return nyearlist.substring(0, nyearlist.length() - 1);
	}
	/*
	 * 得到当前年的后N年的字符串 （含当前年，用 ；隔开，主要用于下拉框）
	 * @param : int 后N年
	 * @param : String 后N年的字符串
	 */
	public static final String getNextAllYear(int n) {
		String nyearlist = "";
		int nyear = Integer.parseInt(getYear());
		for (int t = n; t >= 0; t--) {
			nyearlist += (nyear + t) + ";";
		}
		return nyearlist.substring(0, nyearlist.length() - 1);
	}
	/*
	 * 得到今明前年 （含当前年，用 ；隔开，主要用于下拉框）
	 */
	public static final String getThreeYear() {
		return getNowAllYear(1);
	}
	/*
	 * 得到今明后年 （含当前年，用 ；隔开，主要用于下拉框）
	 */
	public static final String getNextThreeYear() {
		String nyearlist = "";
		int nyear = Integer.parseInt(getYear());
		nyearlist = nyear + ";";
		nyearlist += (nyear + 1) + ";";
		nyearlist += (nyear + 2);

		return nyearlist;
	}

	/*
	 * 得到当前年的前后N年的字符串 （含当前年，用 ；隔开，主要用于下拉框）
	 * @param : int 后N年
	 * @param : String 后N年的字符串
	 */
	public static final String getNowAllYear(int n) {
		String nyearlist = "";
		int nyear = Integer.parseInt(getYear());
		for (int t = n; t > 0; t--) {
			nyearlist += (nyear + t) + ";";
		}
		for (int t = 0; t <= n; t++) {
			nyearlist += (nyear - t) + ";";
		}
		return nyearlist.substring(0, nyearlist.length() - 1);
	}

	/*
	 *  得到年月间隔的ArrayList
	 *  begindate,enddate
	 *           开始日期 结束日期
	 *  @return (ArrayList) --存放返回的年月值   格式   年(4位) - 月(2位)
	 *                     如果有误返回 null
	 */
	public final static ArrayList getYearMonth(
			String begindate,
			String enddate) {

		begindate = tostanddate(begindate);
		enddate = tostanddate(enddate);
		if ((!isDate(begindate)) || (!isDate(enddate))) {
			return null;
		}

		if (stringToTime(begindate).compareTo(stringToTime(enddate)) > 0) {
			return null;
		}
		ArrayList newvec = new ArrayList();

		while (stringToTime(begindate).compareTo(stringToTime(enddate)) <= 0) {
			newvec.add(begindate.substring(0, 7));
			begindate = stringMoveMonth(begindate, 1).substring(0, 7) + "-01";
		}
		return newvec;
	}

	/*
	 * 返回从本日0点0分以来的分钟数
	 * @return : int
	 */
	public static final int getTotMinute() {

		String hours = getHour();
		String minsutes = getMinute();

		return Integer.parseInt(hours) * 60 + Integer.parseInt(minsutes);
	}

	/*
	 * 将字符串转为日期
	 * @param:   String
	 * @return : Date
	 */
	public static final Date stringToDate(String str, String strFormat) {
		SimpleDateFormat sdFormat = new SimpleDateFormat(strFormat);
		Date date = new Date();
		try {
			date = sdFormat.parse(str);
		} catch (Exception e) {
			Date date1 = null;
			return date1;
		}
		return date;
	}

	/*
	 * 将日期转为标准 YYYY-MM-DD 形式字符串
	 * @param: Date
	 * @return : String
	 */
	public static final String dateToYMD(Date dt) {
		SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd");
		String str = "";
		try {
			str = sdFormat.format(dt);
		} catch (Exception e) {
			String s = "";
			return s;
		}
		if (str.equals("1900-01-01")) {
			str = "";
		}
		return str;
	}

	/*
	 * 将日期转为字符串(不带秒的标准字符串)
	 * @param: Date
	 * @return : String
	 */
	public static final String dateToString(Date dt) {
		SimpleDateFormat sdFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		String str = "";
		try {
			str = sdFormat.format(dt);
		} catch (Exception e) {
			String s = "";
			return s;
		}
		if (str.equals("1900-01-01 00:00")) {
			str = "";
		}
		return str;
	}

	/**
	 * 将日期转为指定格式的字符串
	 * @param:   Date
	 * @param:   String 字符串格式
	 * @return : String
	 */
	public static final String dateToString(Date dt, String strFormat) {
		SimpleDateFormat sdFormat = new SimpleDateFormat(strFormat);
		String str = "";
		try {
			str = sdFormat.format(dt);
		} catch (Exception e) {
			String s = "";
			return s;
		}
		if (str.equals("1900-01-01 00:00")) {
			str = "";
		}
		return str;
	}

	/**
	 * 将日期转为汉字形式字符串
	 * @param:   String
	 * @return : String
	 */
	public static final String toChinaDateString(String strDate) {

		Date date = stringToDate(strDate);
		return dateToString(date, "yyyy年MM月dd日 HH:mm");
	}

	/**
	 *  得到两个日期之间的相差天数
	 *  @param  : Date 开始日期
	 *  @param  : Date 结束日期
	 *  @return : int 相差天数
	 */
	public static final int interval(Date first, Date last) {
		int inter = 0;
		inter = (int) ((last.getTime() - first.getTime()) / (long) 0x5265c00);
		return inter;
	}

	/**
	 * 得到指定年的下 N 年
	 *  指定年
	 * @param  num int 下N年
	 * @return String
	 */
	public static final String getAftYear(String nowyear, int num) {
		int numyear = Integer.parseInt(nowyear);
		numyear += num;
		return String.valueOf(numyear);
	}

	/**
	 * 得到指定日期 相差天数的新日期
	 *  指定日期
	 * @param   Days    相差的天数
	 * @return  String 新日期
	 */
	public static final String RelativeDate(String sourceDate, int Days) {

		java.text.SimpleDateFormat d = new java.text.SimpleDateFormat();
		d.applyPattern("yyyy-MM-dd");

		GregorianCalendar cal = new GregorianCalendar();

		java.sql.Date date = null;
		date = java.sql.Date.valueOf(sourceDate);

		cal.setTime(date);
		cal.add(GregorianCalendar.DATE, Days);

		return d.format(cal.getTime());
	}

	/**
	 * 得到当前日期 相差天数的新日期
	 * @param   Days    相差的天数
	 * @return  String 新日期
	 */
	public static final String RelativeDate(int Days) {

		java.text.SimpleDateFormat d = new java.text.SimpleDateFormat();
		d.applyPattern("yyyy-MM-dd");
		GregorianCalendar cal = new GregorianCalendar();
		cal.setTime(new java.util.Date());
		cal.add(GregorianCalendar.DATE, Days);
		return d.format(cal.getTime());
	}

	/**
	 * 返回加密字符串
	 *  需加密的字符串
	 * @return  String
	 */
	public static final String getEncrypt(String temp) {
		String result = "";
		byte result_byte[] = null;
		byte data[] = null;
		Security.addProvider(new SunJCE());
		data = temp.getBytes();
		result = (new BASE64Encoder()).encode(data);
		return result;
	}

	/**
	 * 返回解密字符串
	 *  需解密的字符串
	 * @return String
	 */
	public static final String getDecrypt(String temp) {
		String result = "";
		try {
			byte data[] = (new BASE64Decoder()).decodeBuffer(temp);
			result = new String(data);
		} catch (IOException e) {
			String s = result;
			return s;
		}
		return result;
	}

	private static String makeBh(
			String noqz,
			String bhgs,
			String serial,
			String bhnf,
			String bhyf,
			String tmpcompno,
			javax.servlet.http.HttpServletRequest request,
			String moduname) {
		HttpSession mysess = request.getSession();
		String sbhnf = bhnf;
		if (bhnf.length() < 3) {
			bhnf = "20" + bhnf;
		} else {
			sbhnf = sbhnf.substring(2);
		}
		String strname = "";
		if (mysess.getAttribute(moduname) != null) {
			strname = (String) mysess.getAttribute(moduname);
		}
		bhgs = replaceString(bhgs, "${2位年份}", sbhnf);
		bhgs = replaceString(bhgs, "${4位年份}", bhnf);
		bhgs = replaceString(bhgs, "${月份}", bhyf);
		bhgs = replaceString(bhgs, "${二级单位编号}", tmpcompno);
		bhgs = replaceString(bhgs, "${编号值}", serial);
		bhgs = replaceString(bhgs, "${二级单位前缀}", noqz);
		bhgs = replaceString(bhgs, "${使用SESSION名称}", strname);

		return bhgs;
	}
	/**
	 * 得到自1970年以来 累计的秒数
	 * @return long
	 */
	public static long getOrderTime() {
		return System.currentTimeMillis();
	}

	/**
	 * 依据标准SQL insert 语句，得到PK值
	 *  标准SQL语句
	 * @return String PK值
	 */
	public static String getSqlPk(String sqlValue) {
		sqlValue = sqlValue.substring(sqlValue.indexOf("values(") + 7);
		sqlValue = sqlValue.trim();
		sqlValue = sqlValue.substring(sqlValue.indexOf("'") + 1);
		sqlValue = sqlValue.substring(0, sqlValue.indexOf("'"));
		return sqlValue;
	}
	/**
	 * 按长度加回车编码
	 * @param strSource
	 * @param reallength
	 * @return
	 */
	public final static String addEnter(String strSource, int reallength) {
		int nlength = ((int) strSource.length() / reallength);

		String retStr = "";

		for (int s = 0; s < nlength; s++) {
			String tmpstr =
					strSource.substring(s * reallength, (s + 1) * reallength)
							+ "\n";
			retStr = retStr + tmpstr;
		}

		return retStr;
	}

	/**
	 * 字符串替换
	 * @param strSource
	 * @param strFrom
	 * @param strTo
	 * @return
	 */
	public final static String replace(
			String strSource,
			String strFrom,
			String strTo) {

		String strDest = "";
		int intFromLen = strFrom.length();
		int intPos;

		while ((intPos = strSource.indexOf(strFrom)) != -1) {
			strDest = strDest + strSource.substring(0, intPos);
			strDest = strDest + strTo;
			strSource = strSource.substring(intPos + intFromLen);
		}
		strDest = strDest + strSource;

		return strDest;
	}

	//得到某个月的实际天数
	public static int getRealDay(String year, String month) {
		int nend = 31;
		if (month.equals("2") || month.equals("02")) {
			if (isLeap(Integer.parseInt(year)))
				nend = 29;
			else
				nend = 28;
		}
		if (month.equals("1") || month.equals("01")) {
			nend = 31;
		}
		if (month.equals("3") || month.equals("03")) {
			nend = 31;
		}
		if (month.equals("4")
				|| month.equals("04")
				|| month.equals("6")
				|| month.equals("06")
				|| month.equals("9")
				|| month.equals("09")) {
			nend = 30;
		}
		if (month.equals("5")
				|| month.equals("05")
				|| month.equals("7")
				|| month.equals("07")
				|| month.equals("8")
				|| month.equals("08")) {
			nend = 31;
		}
		if (month.equals("10") || month.equals("12")) {
			nend = 31;
		}
		if (month.equals("11")) {
			nend = 30;
		}
		return nend;
	}
	/**
	 * 得到某个月的所有天数字符串
	 * @param year
	 * @param month
	 * @return
	 */
	public static String getAllListDay(String year, String month) {
		int nbegin = 1;
		int nend = 31;
		if (month.equals("2") || month.equals("02")) {
			if (isLeap(Integer.parseInt(year)))
				nend = 29;
			else
				nend = 28;
		}
		if (month.equals("1") || month.equals("01")) {
			nend = 31;
		}
		if (month.equals("3") || month.equals("03")) {
			nend = 31;
		}
		if (month.equals("4")
				|| month.equals("04")
				|| month.equals("6")
				|| month.equals("06")
				|| month.equals("9")
				|| month.equals("09")) {
			nend = 30;
		}
		if (month.equals("5")
				|| month.equals("05")
				|| month.equals("7")
				|| month.equals("07")
				|| month.equals("8")
				|| month.equals("08")) {
			nend = 31;
		}
		if (month.equals("10") || month.equals("12")) {
			nend = 31;
		}
		if (month.equals("11")) {
			nend = 30;
		}
		String strday = "";
		for (int n = nbegin; n <= nend; n++) {
			strday += n + ";";
		}
		return strday.substring(0, strday.length() - 1);
	}
	//----------------------------------------------------------------------------
	//得到当年的前N年 （含当前年）
	//----------------------------------------------------------------------------
	public static String getAllYearS(int n) {
		String nyearlist = "";
		int nyear = Integer.parseInt(getYear());
		for (int t = 0; t < n; t++) {
			nyearlist += (nyear - t) + ";";
		}
		return nyearlist.substring(0, nyearlist.length() - 1);
	}


	//返回两时间差别(单位分钟)
	public final static int getDStime(String strbef, String strlas) {

		int ny1 = Integer.parseInt(strbef.substring(0, 4));
		int nM1 = Integer.parseInt(strbef.substring(5, 7));
		int nd1 = Integer.parseInt(strbef.substring(8, 10));
		int nh1 = Integer.parseInt(strbef.substring(11, 13));
		int nm1 = Integer.parseInt(strbef.substring(14, 16));

		int ny2 = Integer.parseInt(strlas.substring(0, 4));
		int nM2 = Integer.parseInt(strlas.substring(5, 7));
		int nd2 = Integer.parseInt(strlas.substring(8, 10));
		int nh2 = Integer.parseInt(strlas.substring(11, 13));
		int nm2 = Integer.parseInt(strlas.substring(14, 16));

		int nDiffDay = 0;
		int nBefDay = 0;
		int nLasDay = 0;

		nBefDay =
				ny1 * 365 * 24 * 60
						+ (int) nBefDay / 4
						+ nd1 * 24 * 60
						+ StaticTools.getMonthDay(ny1, nM1) * 24 * 60
						+ nh1 * 60
						+ nm1;

		nLasDay =
				ny2 * 365 * 24 * 60
						+ (int) nLasDay / 4
						+ nd2 * 24 * 60
						+ StaticTools.getMonthDay(ny2, nM2) * 24 * 60
						+ nh2 * 60
						+ nm2;

		return nLasDay - nBefDay;

	}

	public static String getCLOBContent(ResultSet rs, int clobidx)
			throws SQLException {
		oracle.sql.CLOB clobField = ((OracleResultSet) rs).getCLOB(clobidx);
		if (clobField == null)
			return "";
		long clen = clobField.length();
		String templen = String.valueOf(clen);
		if (templen == null)
			return "";

		if (clen < 1)
			return "";

		char clobArray[] = new char[(int) clen];
		int readednum = clobField.getChars(1, (int) clen, clobArray);

		StringBuffer sb = new StringBuffer();
		sb.append(clobArray);
		if (sb == null)
			return "";
		if (sb.toString() == null)
			return "";
		return sb.toString();
	}

	//返回当前日期所属旬
	public static String xunshu(String strDate) {
		String retstr = "";
		if (strDate.trim().equals("") || strDate.trim().equals("")) {
			return retstr;
		}
		if (!isDate(strDate)) {
			return retstr;
		}
		strDate = tostanddate(strDate);
		int day = Integer.parseInt(strDate.substring(8, 10));
		if (day <= 10) {
			retstr = "上";
		} else if (day <= 20) {
			retstr = "中";
		} else {
			retstr = "下";
		}
		return retstr;
	}

	/**
	 *
	 * 得到上年月
	 * [0] 年
	 * [1] 月
	 *
	 * */

	public static String[] makeYearMonthUp(String year, String month) {

		String[] year_month_last = new String[2];

		int year_last_value;
		int month_last_value;

		try {

			int year_value = Integer.valueOf(year).intValue();
			int month_value = Integer.valueOf(month).intValue();

			if (month_value - 1 == 0) {

				month_last_value = 12;
				year_last_value = year_value - 1;

			} else {

				month_last_value = month_value - 1;
				year_last_value = year_value;
			}

			year_month_last[0] = year_last_value + "";
			year_month_last[1] = month_last_value + "";

			return year_month_last;

		} catch (Exception e) {

			year_month_last[0] = "year error";
			year_month_last[1] = "month error";

			return year_month_last;
		}

	}
	/**
	 * 数字大小比较
	 *
	 * 如果 a >b 则返回 1
	 * 如果 a <b -1
	 * 如果 a =b 0
	 * */
	public static String compareNum(String a, String b) {

		double x = Double.parseDouble(a);
		double y = Double.parseDouble(b);

		if (x > y) {

			return "1";
		}
		if (x < y) {

			return "-1";
		}
		if (x == y) {

			return "0";
		}

		return "";
	}
	/**
	 * 日期范围大小比较
	 *
	 * 如果 strDate 在 begindate 和 enddate 范围内则返回 1
	 * 如果 strDate 在 begindate 和 enddate 范围之前则返回 0
	 * 如果 strDate 在 begindate 和 enddate 范围之后返回 2
	 * */
	public static String comparebetweenDate(
			String strDate,
			String begindate,
			String enddate) {
		String result = "0";
		try {

			if (compareDate(begindate, strDate)
					&& compareDate(strDate, enddate)) {
				result = "1";

			} else {
				if (!compareDate(begindate, strDate)) {
					result = "0";

				}
				if (!compareDate(strDate, enddate)) {
					result = "2";

				}

			}

		} catch (Exception e) {
			System.out.println("" + e);

		}
		return result;
	}

	/**
	 * 日期大小比较
	 *
	 * 如果 enddate 晚于 begindate 则返回 真
	 *
	 * */
	public static boolean compareDate(String begindate, String enddate) {
		boolean result = true;
		try {
			Date d1 = stringToDate(begindate, "yyyy-MM-dd");
			Date d2 = stringToDate(enddate, "yyyy-MM-dd");

			if (d2.after(d1)) {

				return true;

			} else if (d1.after(d2)) {

				return false;

			}

		} catch (Exception e) {
			System.out.println("" + e);

		}
		return result;
	}
	//返回旬数
	public static String getXs(String inputdate) {
		if (StaticTools.isDate(inputdate)) {
			inputdate = StaticTools.tostanddate(inputdate);
			String days = inputdate.substring(8);
			int ndays = Integer.parseInt(days);
			if (ndays < 11)
				return "上";
			if (ndays < 21)
				return "中";
			return "下";
		}
		return "";
	}

	/**
	 * 将字符串变成(case When xxx is null then 0 else xxx end)
	 * */
	public static String makeCaseWhenStr(String str) {
		if(str==null||str.equals(""))
			str="0";
		String result =
				"(case when " + str + " is null then 0 else " + str + " end)";
		return result;
	}
	/**
	 * 将字符串为空的替换成0
	 * */
	public static String makeNulltoZero(String str) {
		String result = str;
		if (str.equals("")) {
			result = "0";
		}
		return result;
	}

	/**
	 * 得到两个时间的差
	 * @return
	 */
	public final static String getDiffTwoTime(
			String beginTime,
			String endTime) {
		SimpleDateFormat dfs = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		java.util.Date end = null;
		java.util.Date begin = null;
		try {
			begin = dfs.parse(beginTime);
			end = dfs.parse(endTime);
		} catch (ParseException e) {
			return "error";
		}

		long between = (end.getTime() - begin.getTime()) / 1000;
		//除以1000是为了转换成秒
		long day1 = between / (24 * 3600);
		long hour1 = between % (24 * 3600) / 3600;
		long minute1 = between % 3600 / 60;
		long second1 = between % 60 / 60;

		String msg = "";
		if (day1 > 0) {
			msg += day1 + "天";
		}

		if (day1 > 0 || hour1 > 0) {
			msg += hour1 + "小时";
		}

		if (minute1 > 0) {
			msg += minute1 + "分";
		}
		return msg;
	}

	/**
	 * 判断使用人员级别
	 * @param jb
	 * @param dyjb
	 * @return
	 */
	public final static String judgeSyjb(String jb, String dyjb) {
		if (dyjb.equals(""))
			return "1";

		if (dyjb.equals("科级以上")) {
			if (jb.equals("部门级领导")) {
				return "1";
			} else {
				if (jb.equals("矿级领导")) {
					return "1";
				} else {
					return "2";
				}
			}
		}
		if (dyjb.equals("矿级以上")) {
			if (jb.equals("矿级领导")) {
				return "1";
			} else {
				return "2";
			}
		}
		return "1";
	}
	/**
	 * 替换数据库数据，适用于CI系统向其它系统倒表
	 */
	public final static String replaceSjk(String sjsql, String zfc) {
		sjsql = StaticTools.replace(sjsql, "'", "[");
		sjsql = StaticTools.replace(sjsql, "t_ci_", zfc);
		sjsql = StaticTools.replace(sjsql, "t_ci_", zfc);
		sjsql = StaticTools.replace(sjsql, "t_ci_", zfc);
		sjsql = StaticTools.replace(sjsql, "t_ci_", zfc);
		sjsql = StaticTools.replace(sjsql, "t_ci_", zfc);
		sjsql = StaticTools.replace(sjsql, "t_ci_", zfc);
		sjsql = StaticTools.replace(sjsql, "t_ci_", zfc);
		sjsql = StaticTools.replace(sjsql, "t_ci_", zfc);

		return sjsql;
	}
	public final static String replaceSjkHj(String sjsql) {
		return replaceSjk(sjsql, "t_ci_");
	}
	public final static String replaceSjkErp(String sjsql) {
		return replaceSjk(sjsql, "t_ci_");
	}

	/**
	 * 返回带有数值的数学表达式
	 * @param vgs string    公式
	 * @param mapset HashMap mapset 公式中对应字段的值
	 * @return  string 返回带有值的公式
	 */
	public static String getVFomula(String vgs, HashMap mapset) {
		String tmp = "", field = "", tmpstr = "", setvalue, s1 = "", s2 = "";
		String vstr = vgs;
		int p = 0, q = 0, x = 0, l = 0;

		l = vstr.length();

		String f1 = vstr.substring(0, 1);
		if (f1.equals("[")) {
			p = vstr.indexOf("[");
			q = vstr.indexOf("]");
			field = vstr.substring(1, q);

			setvalue = (String) mapset.get("[" + field + "]");

			if (setvalue.equals(""))
				setvalue = "0";
			if (q < (l - 1))
				vstr = setvalue + vstr.substring(q + 1);
			else
				vstr = setvalue;

		}

		while (vstr.indexOf("[") > 0) {
			p = vstr.indexOf("[");
			q = vstr.indexOf("]");
			s1 = vstr.substring(0, p);

			if (q < (l - 1))
				s2 = vstr.substring(q + 1);
			else
				s2 = "";
			field = vstr.substring(p + 1, q);

			setvalue = (String) mapset.get("[" + field + "]");
			if (setvalue.equals(""))
				setvalue = "0";
			vstr = s1 + setvalue + s2;
		}
		return vstr;
	}
	/**
	 * 返回数值都为1的数学表达式
	 *  vgs   公式
	 *  mapset 公式中对应字段的值
	 * @return  string 返回数值都为1
	 */
	public static String getTestFomula(String vgs) {
		String tmp = "", field = "", tmpstr = "", s1 = "", s2 = "";
		String vstr = vgs;
		int p = 0, q = 0, x = 0, l = 0;

		l = vstr.length();
		String setvalue = "1";

		String f1 = vstr.substring(0, 1);
		if (f1.equals("[")) {
			p = vstr.indexOf("[");
			q = vstr.indexOf("]");
			field = vstr.substring(1, q);
			if (q < (l - 1))
				vstr = setvalue + vstr.substring(q + 1);
			else
				vstr = setvalue;

		}

		while (vstr.indexOf("[") > 0) {
			p = vstr.indexOf("[");
			q = vstr.indexOf("]");
			s1 = vstr.substring(0, p);

			if (q < (l - 1))
				s2 = vstr.substring(q + 1);
			else
				s2 = "";
			field = vstr.substring(p + 1, q);

			vstr = s1 + setvalue + s2;
		}
		return vstr;
	}

	/**
	 * 生成 不同编码的文本文件
	 */
	//TXT只支持4种编码：ANSI/UNICODE/UNICODE BE/UTF-8

	public static boolean writeStringToFile(
			String fileName,
			String content,
			String enc) {
		File file = new File(fileName);

		try {
			if (file.isFile()) {
				file.deleteOnExit();
				file = new File(file.getAbsolutePath());
			}
			OutputStreamWriter os = null;
			if (enc == null || enc.length() == 0) {

				os = new OutputStreamWriter(new FileOutputStream(file));
			} else {
				os = new OutputStreamWriter(new FileOutputStream(file), enc);
			}
			os.write(content);
			os.close();
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}
	public static boolean writeStringToFile(
			String fileName,
			Vector contentarr,
			String enc) {
		File file = new File(fileName);

		try {
			if (file.isFile()) {
				file.deleteOnExit();
				file = new File(file.getAbsolutePath());
			}
			OutputStreamWriter os = null;
			if (enc == null || enc.length() == 0) {
				os = new OutputStreamWriter(new FileOutputStream(file));
			} else {
				os = new OutputStreamWriter(new FileOutputStream(file), enc);
			}
			for (int s = 0; s < contentarr.size(); s++) {
				String content = (String) contentarr.get(s);
				os.write(content);
			}
			os.close();
		} catch (Exception e) {
			e.printStackTrace();
			return false;
		}
		return true;
	}

	public static String[] getNextNY(String year, String month) {

		String[] ny = new String[2];
		int y = Integer.parseInt(year);
		int m = Integer.parseInt(month);
		if (m == 12) {
			y++;
			m = 1;
		} else {
			m++;
		}
		ny[0] = "" + y;
		ny[1] = "" + m;

		return ny;
	}

	/**
	 *
	 * <p>Function: getTjdate</p>
	 * <p>Description: 获得统计年份和月份</p>
	 * <p>return value:Hashtable</p>
	 * <p>History:
	 *    2009-10-14 17:13:56 wangkun
	 * </p>
	 *
	 */
	public static Hashtable getTjdate(String date) {
		Hashtable result = new Hashtable();

		if (!StaticTools.isDate(date)) {
			result.put("result", "error");
			return result;
		} else {
			result.put("result", "ok");
			int year = Integer.parseInt(StaticTools.getYearStr(date));
			int month = Integer.parseInt(StaticTools.getMonthStr(date));
			int day = Integer.parseInt(StaticTools.getDayStr(date));

			if (day <= 26) {
				result.put("month", month + "");
				result.put("year", year + "");
				return result;
			} else {
				if (month == 12) {
					result.put("month", month + "");
					result.put("year", year + "");
					return result;
				} else {
					result.put("month", (month + 1) + "");
					result.put("year", year + "");
					return result;
				}
			}
		}
	}

	/**
	 * 根据最小二乘法计算趋势线公式 y=bx+a 的a,b值，
	 * 并根据算出来的a,b值计算出每个x对应的y值，
	 * 即为趋势线的y值，返回y值数组，直接用于echarts
	 *
	 * @param
	 *      values - n个数据的数组
	 * @return
	 *      ys - 计算出的n个数据的趋势线数据数组
	 */
	public static double[] calTrendline(double[] values) {
    /*
     * 根据最小二乘法求解，需要以下参数
     * ∑x, ∑y, ∑xx, ∑xy
     * 此处x取单位1即可，依次++
     */
		int n = values.length;
		int sumX = 0;
		double sumY = 0.0;
		int sumXX = 0;
		double sumXY = 0.0;
		for (int i = 1; i <= n; i ++) {
			sumX += i;
			sumY += values[i - 1];
			sumXX += (i * i);
			sumXY += (i * values[i - 1]);
		}

		// 求a,b
		double b = (n * sumXY - sumX * sumY) / (n * sumXX - sumX * sumX);
		double a = (sumY - b * sumX) / n;
		System.out.println(a + "," + b);

		// 返回趋势线y值
		double[] ys = new double[n];
		for (int i = 1; i <= n; i ++) {
			// 保留3位小数，绝对够准确了
			BigDecimal bd = new BigDecimal( b * i + a );
			ys[i - 1] = bd.setScale(3, BigDecimal.ROUND_HALF_UP).doubleValue();
		}

		return ys;
	}

	/**
	 * 判断字符是否为中文
	 * @param c
	 * @return
	 */
	private static boolean isChinese(char c) {
		Character.UnicodeBlock ub = Character.UnicodeBlock.of(c);
		if (ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS
				|| ub == Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS
				|| ub == Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A
				|| ub == Character.UnicodeBlock.GENERAL_PUNCTUATION
				|| ub == Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION
				|| ub == Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS) {
			return true;
		}
		return false;
	}

	/**
	 * 判断中文是否乱码
	 * @param strName
	 * @return
	 */
	public static boolean isMessyCode(String strName) {
		Pattern p = Pattern.compile("\\s*|\t*|\r*|\n*");
		Matcher m = p.matcher(strName);
		String after = m.replaceAll("");
		String temp = after.replaceAll("\\p{P}", "");
		char[] ch = temp.trim().toCharArray();
		float chLength = 0 ;
		float count = 0;
		for (int i = 0; i < ch.length; i++) {
			char c = ch[i];
			if (!Character.isLetterOrDigit(c)) {
				if (!isChinese(c)) {
					count = count + 1;
				}
				chLength++;
			}
		}
		float result = count / chLength ;
		if (result > 0.4) {
			return true;
		} else {
			return false;
		}
	}


}